Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Angry Problems with classes

    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:
    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!

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Maybe I forgot to add: $db->execute() returns a class and $rs->Fetchrow should() be there (this is where the error comes from).

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    De gustibus non est disputandum.

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I feel soo Inteligent now... . 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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •