View Full Version : Problems with classes

05-11-2004, 04:53 PM
I don't know how to put it but I get the error even if I did everything right (some peple said it solved their problem)

The code:
// Connect to database.
$db = ADONewConnection($db_type);
$db -> debug = 0;
$db -> Connect($db_host, $db_user, $db_pass, $db_name);

class session

function start()
global $db;
$rs = $db->Execute("SELECT * FROM sessions");
$session_data = $rs->FetchRow();
At first I didn't make $db global. I got the "Call to a member function on a non-object" error. After reading some forums I found out that it has to be global (there was even an examle with ADoDB. It worked for them but not for me). That should have solved the problem but it didn't. Why won't it work? Please help!
Thank you!

05-11-2004, 06:03 PM
Maybe I forgot to add: $db->execute() returns a class and $rs->Fetchrow should() be there (this is where the error comes from).

05-11-2004, 08:34 PM
I usually do work with a different database abstraction layer (Pear::DB), but I suspect things work similar with AdoDB. Anyway, you are extremely optimistic with your code. Did you check that

a) your connection has been established correctly? Is the database the correct one?
b) did your query excecute correctly? In Pear::DB, whenever a query fails, you get an error object back. Doesn't seem to be the case in your example, so I would just check with var_dump($rs); what kind of data type actually is in $rs.

That should help you narrowing down the sources of the error. If you need further help, tell us what PHP says is in $rs.

05-11-2004, 08:46 PM
I feel soo Inteligent now... :o . Thanks for your help. (I forgot about something very stupid.) The query was empty so AdoDB made the $rs empty too. I spelled sessions wrong in the mysql table...