Suggestion for porting function to PHP5??

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hello, I was hoping someone could provide some insight as to the best
approach to take in porting over a function I use in quite a few spots
from PHP4 to PHP5. Basically, I have a db wrapper class that I use
called DBConn (this is the PHP5 ported definition for the members, PHP4
was the same except "private" was "var"):

class DBConn
    private $hDB;   //db link
    private $bConnected;    //db link status
    private $bInTX;    //current transaction status, used to avoid
    private $hResult;  //result link
    private $iNumResultRows;

with those being the members.  Within this class, I also have the
following method (this is the PHP4 definition for the method):

function doEscapeString($a_stInputString)
    if (isset($this->hDB)) {
        return mysql_real_escape_string($a_stInputString, $this->hDB);

    $l_stServer = 'localhost';
    $l_stUsername = 'escape_tester';
    $l_stPassword = 'a1b2c3d4';

    $l_hDBForFunc =
    return mysql_real_escape_string($a_stInputString, $l_hDBForFunc);

"escape_tester" is a completely unprivileged account, used only for the
escape_string function connection when necessary. As you can see, in
PHP4, since it doesn't do such strict checking, you are allowed to
check for the existence of the "$this" variable prior to creating the
new connection, even when you call the method statically via
DBConn::doEscapeString. Obviously, this has changed in PHP5 thanks to
the new object implementation, and "$this" never exists for a static
public function (as you have to change doEscapeString to in order to
not cause an error when calling it statically in your code). Here is
the PHP5 version:

public static function doEscapeString($a_stInputString)
    $l_stServer = 'localhost';
    $l_stUsername = 'escape_tester';
    $l_stPassword = 'a1b2c3d4';

    $l_hDBForFunc =
    return mysqli_real_escape_string($l_hDBForFunc,$a_stInputString);

What I'm trying to d is figure out a way that I can still have a test
for the existence of a current db link prior to ALWAYS creating a new
connection for each call to doEscapeString. There are quite a few spots
in my code where a "$l_roDBConn = new DBConn" was created prior to ever
calling "doEscapeString". In those cases, I would later use
"$l_roDBConn->doEscapeString(xxx)" instead of calling it statically...
thus reusing the existing connection. This no longer is possible with
PHP5 though unfortunately. Any suggestions as to what could be done to
regain the old PHP4 functionality? Thanks in advance for any and all


Site Timeline