Jump to content

3 days running around these errors, please help!


scottybwoy

Recommended Posts

Hi All,

I recieve this Error :

PHP Fatal error: Call to a member function fetchRow() on a non-object in C:\root\to\my\framework\lib.session_handler.php on line 36

What I think my code is doing, is returning the result of a query to a variable called $result and is then using it in the wrong fashion (i.e calling the function on the non-object) that it loops round and returns the error above.  I don't want it to do that.  But I don't really understand what I do want it to do.  Here is my code below :
[code]
        function sess_read($key) {
                global $dbi, $DEBUG, $SESS_LIFE;

                $statement = "SELECT value FROM sessions WHERE sesskey = $key AND expiry >" . time();

                $result = $dbi->query($statement);

                if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
                $row = $result->fetchRow();
                if ($row) {
                  return $row->value;
                }
                return false;
        }
[/code]

Could this occur as a result of not talking to DBI.php or NULL field in sesskey, and not of my php code.  And could someone expain to me what this process it doing,  I already understand the query bit tho  ;)

Thanks ppl
Link to comment
Share on other sites

I don't know anything about the DBI interface, but it looks to me that the fetchRow function belongs to the class that generated $dbi. If so, then I guess the query should be something like:

[code]$row = $dbi->fetchRow($result);[/code]

Ronald  ;D
Link to comment
Share on other sites

That looked as though you were on the right lines but just returned with a different Error :

PHP Fatal error: Call to undefined method DBI::fetchRow() in C:\Inetpub\wwwroot\demo\framework\lib.session_handler.php on line 36

Cheers for the quick response
Link to comment
Share on other sites

Firstly, I always thought that DBI was a db layer interface for Perl!(?).

Secondly, whyen I look at the site that gives some sample, such as [url=http://www.uklinux.net/support/DBI.php]http://www.uklinux.net/support/DBI.php[/url], I see the following fetch-look-alike commands, but not the fetchRow.

[code]
@row_ary  = $sth->fetchrow_array;
$ary_ref  = $sth->fetchrow_arrayref;
$hash_ref = $sth->fetchrow_hashref;
$ary_ref  = $sth->fetchall_arrayref;

where $sth is the statement handle object.
[/code]

So no fetchRow method found in that DBI documentation!

Link to comment
Share on other sites

function fetchRow ()

Is defined it the PEAR DB Library under DB.php and does this :

/**
    * Fetch and return a row of data (it uses driver->fetchInto for that)
    * @param int $fetchmode  format of fetched row
    * @param int $rownum    the row number to fetch
    *
    * @return  array a row of data, NULL on no more rows or PEAR_Error on error
    */

fetchInto does this :

/**
    * Fetch a row of data into an existing variable.
    *
    * @param  mixed $arr        reference to data containing the row
    * @param  int  $fetchmode  format of fetched row
    * @param  int  $rownum    the row number to fetch
    *
    * @return  mixed  DB_OK on success, NULL on no more rows or
    *                a DB_Error object on error
    */

These functions can be found ported with the PEAR Framework if anyone wants it.
However for this project I don't actually need Database abstraction but I do not know how to go about re-writing what it is trying to do without having to use PEAR.  I know that it will probably be easier to solve this problem, but I feel I would learn more if someone helped me with this.

This problem may help to solve this problem swiftly though if anyone can see it?
[code]
<?php
function connect()
      {

        // connect to the database


        $status = $this->dbh = DB::connect($this->db_url);//error lies after dbh expected ';' & '}'

        if (DB::isError($status))
        {
            $this->connected = FALSE;

            $this->error = $status->getMessage();

        } else {

            $this->connected = TRUE;
        }


        return $this->connected;

      }
?>
[/code]

In addition to this I have noticed in my editor, that function 'connect'() shows in green like 'define' 'stripos' and other built in php functions, although I could not find it in the php manual.

Further experimentation I changed this line in lib.session_handler.php
[code]
$DB_URL = "mssql://user:pass@localhost:/sessions";

//into

$DB_URL = 'mssql_connect("localhost", "user", "pass")
  or die "Could not connect to database"
mssql_select_db("sessions") or die
"Could not select database"';
[/code]

And now get this error :

PHP Fatal error: Call to undefined method DB_Error::query() in C:\Inetpub\wwwroot\database\classes\class.DBI.php on line 83

Within this Function

[code]<?php
function query($statement)
      {

        $result =  $this->dbh->query($statement);

        if (DB::isError($result))
        {

            $this->setError($result->getMessage());

            return null;

        } else {

            return $result;
        }


      }
?>[/code]
Link to comment
Share on other sites

Not sure if my amendmet above really helped, looking at the way it's processed in PEAR's DB.php so changed it back to in lib.session_handler.php:
[code]
<?php
$DB_URL = "mssql://user:pass@localhost:/sessions";
?>
[/code]
Although I think it is passed to the Database Abstraction Class called class.DBI.php so changed the function from the commented block to the uncommented block like so :
[code]
<?php

function connect()
      {

        // connect to the database

        /*
$status = $this->dbh = DB::connect($this->db_url);

        if (DB::isError($status))
        {
            $this->connected = FALSE;

            $this->error = $status->getMessage();

        } else {

            $this->connected = TRUE;
        }


        return $this->connected;
*/

mssql_connect("localhost", "tecnical", "micro")
  or die;
"Could not connect to database";
mssql_select_db("sessions") or die;
"Could not select database";

      }
?>
[/code]

Only to get this error :

PHP Warning: mssql_query() [function.mssql-query]: message: Invalid column name 'pplg3pvool34o0ecl98v0d8101'. (severity 16) in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 31 PHP Warning: mssql_query() [function.mssql-query]: Query failed in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 31 PHP Fatal error: Call to a member function fetchRow() on a non-object in C:\Inetpub\wwwroot\database\classes\lib.session_handler.php on line 34

Which shows it is connecting to the database after what I have done, but looks as though it is using the session key as a column name or has passed some crap through the DB.php

What do you think people?

Here's the query in lib.session_handler.php :

[code]
<?php

function sess_read($key) {
                global $dbi, $DEBUG, $SESS_LIFE;

                $result = mssql_query("SELECT value FROM sessions WHERE sesskey = $key AND expiry > " . time());

                if ($DEBUG) echo "sess_read: $statement <br>result: $result<br>";
                $row = $result->fetchRow();
                if ($row) {
                  return $row->value;
                }

                return false;
        }
[/code]
Link to comment
Share on other sites

Is this a valid MSSQL Query ?
[code]
<?php

$result = mssql_query("SELECT value FROM sessions WHERE sesskey = $key AND expiry > " . time());

?>
[/code]

In my example in the post above, there should be nothing interfering with the query is there?

If so why do I get this error, and how is a session key generated?
Link to comment
Share on other sites

I have now also noted that when I query the database on it's own I find that there is no session key stored in there at all but when I press refresh, it gives a new key for the column name in the error and also it doesn't seem to have any time value at the end of the session key string.

:'([color=red]Can some one please read through and help me find the answers cos it's really starting to bug me.  Many Thanks[/color] :'(
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.