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
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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.