Jump to content


Photo

3 days running around these errors, please help!


  • Please log in to reply
9 replies to this topic

#1 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 02 August 2006 - 01:56 PM

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

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


#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 02 August 2006 - 02:04 PM

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:

$row = $dbi->fetchRow($result);

Ronald  ;D
RTFM is an almost extinct art form, it should be subsidized.

#3 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 02 August 2006 - 02:13 PM

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

#4 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 03 August 2006 - 08:45 AM

Does anyone understand more on this, it's still bugging me

#5 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 09 August 2006 - 01:54 PM

*Probe*

Am still also having trouble with this

#6 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 09 August 2006 - 03:00 PM

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 http://www.uklinux.net/support/DBI.php, I see the following fetch-look-alike commands, but not the fetchRow.

@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.

So no fetchRow method found in that DBI documentation!


RTFM is an almost extinct art form, it should be subsidized.

#7 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 09 August 2006 - 03:08 PM

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

      }
?>

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
$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"';

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

<?php
function query($statement)
      {

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

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

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

            return null;

         } else {

            return $result;
         }


      }
?>


#8 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 10 August 2006 - 11:45 AM

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:
<?php
$DB_URL = "mssql://user:pass@localhost:/sessions";
?>
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 :
<?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";

      }
?>

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 :

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


#9 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 10 August 2006 - 02:49 PM

Is this a valid MSSQL Query ?
<?php

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

?>

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?

#10 scottybwoy

scottybwoy
  • Members
  • PipPipPip
  • Advanced Member
  • 532 posts
  • LocationUK

Posted 11 August 2006 - 10:46 AM

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.

:'(Can some one please read through and help me find the answers cos it's really starting to bug me.  Many Thanks :'(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users