Fatal error: Call to a member function on a non-object

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IXxAlnxXI
Forum Newbie
Posts: 6
Joined: Fri Apr 20, 2007 4:32 pm

Fatal error: Call to a member function on a non-object

Post by IXxAlnxXI »

i get an error on like 386, which is the $db->Close();, i get that fatal error for everyting the database connection is closed, below the $db-Close(); is my function which closes the database (it's in a class). anyone know why i keep getting the fatal error? any help is appreciated, thanks
'Fatal error: Call to a member function on a non-object'

Code: Select all

<?php

   $db->Close();
   
?>

Code: Select all

function Close()
      {
         mysql_close( $this->db_link);
      }
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

echo 'db: '; var_dump($db);
$db->Close();
IXxAlnxXI
Forum Newbie
Posts: 6
Joined: Fri Apr 20, 2007 4:32 pm

Post by IXxAlnxXI »

that doesn't seem to work, but thanks for the help thoug.h i still can't get it ><. the headerflie has a class, which has 2 functions: Close() and Connect(), Connect() is called and works fine, but Close() is giving the error
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

The reason volka asked you to try that is to post the result back here, so we can be certain the object exists.
IXxAlnxXI
Forum Newbie
Posts: 6
Joined: Fri Apr 20, 2007 4:32 pm

Post by IXxAlnxXI »

oooh, alright, so i post the code and reply back the results, correct?
IXxAlnxXI
Forum Newbie
Posts: 6
Joined: Fri Apr 20, 2007 4:32 pm

Post by IXxAlnxXI »

after pasting volka's code, it shows this, the "db:bool(true)"

db: bool(true)
Fatal error: Call to a member function on a non-object in /home/.frumisera/danial/rtndev.roadtripnation.com/watch.php on line 386
IXxAlnxXI
Forum Newbie
Posts: 6
Joined: Fri Apr 20, 2007 4:32 pm

Post by IXxAlnxXI »

any suggestions?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Just so you know bumping prior to 24 hours since your last post is a violation of our rules.

Please take the time to read our forum rules, so you don't violate our rules again :wink:
IXxAlnxXI
Forum Newbie
Posts: 6
Joined: Fri Apr 20, 2007 4:32 pm

Post by IXxAlnxXI »

sorry about that :/ please don't consider this a bump, either, it's a public apology :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

IXxAlnxXI wrote:db: bool(true)
Fatal error: Call to a member function on a non-object in /home/.frumisera/danial/rtndev.roadtripnation.com/watch.php on line 386
$db is not an object but a boolean, like $db = true;
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Post the code where $db is being assigned. Is Close() a method of a class, or is it just a user-defined function?
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Case 1 : You are trying to close the connection after the class has been destructed.
Case 2: The MySQL connection has been closed by some other functions or classes.

EDIT
-------------------------------
:teach: :drunk: :mrgreen: :lol: Yes I've made this post without CAPS everywhere.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

neel_basu, please note that a var_dump of the variable in question returned bool(true), it's not an object.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Oh! Sorry I've overlooked db: bool(true)
Post Reply