Jump to content

Converting PHP3 to PHP5


Cognito

Recommended Posts

Hi Guys,

 

I'm trying to convert the following code from php3 syntax to php5.

I've managed to convert everything except the mysql_fetch_row segment.

 

For some reason I always get the error:

 

mysql_fetch_row(): supplied argument is not a valid MySQL result resource

 

function sess_read($key) {
    $qry = "SELECT data FROM sessions WHERE sessID = '$key' AND expires > ".time();

// New mQuery Call
    $res = new DB;
    $res->mQuery($qry, __LINE__);   
    if (list($value) = mysql_fetch_row($res)) {
    return $value;
    }
    return false;
}

 

The code for the function mQuery in the class DB is:

 

    function mQuery($sql, $line=-1, $link=''){
        global $mysqlLink;
        $res = @ mysql_query($sql);
        if (!$res){
            trigger_error("Query failure at <i style='color:black'>$sql</i>.<br> MySQL said: ".mysql_error()."¼".$line, E_USER_ERROR);
        }
        return $res;
    }

 

Hope you can help guide me in the right direction :)

Link to comment
https://forums.phpfreaks.com/topic/90655-converting-php3-to-php5/
Share on other sites

You're confusing your variable names and their scope

Change this :

function sess_read($key) {
    $qry = "SELECT data FROM sessions WHERE sessID = '$key' AND expires > ".time();

// New mQuery Call
    $res = new DB;   // <==== this is an object not a query result!
    $queryResult = $res->mQuery($qry, __LINE__);   
    if (list($value) = mysql_fetch_row($queryResult)) {
    return $value;
    }
    return false;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.