...

View Full Version : Fatal error



Lyconpire
04-26-2006, 10:34 PM
Fatal error: Call to a member function on a non-object

All this is from a php book i been reading. I guess the error is to do with this bit on line 17

$result = $db_conn->query($query);
if ($result->num_rows >0 )

Am guessing i have to define the object or something? :confused: this what the book tells me to do code for code i don't understand why it don't work?

chump2877
04-26-2006, 11:06 PM
I suggest you read this article : http://www.phpfreaks.com/tutorials/48/0.php

on how to write and use PHP classes.

At some point you need to include the class and intialize it (before you use the class):


include "MyClass.class.php";

$myclass = &New MyClass;

Then you can accesss the methods/properties inside the class using $myclass:


$myclass->method();

or


$myclass->property = "whatever";

Lyconpire
04-26-2006, 11:07 PM
lol what... ok erm i will read that thanks ;-)

is there a fix for my code that i summited or it to far gone to fix?

marek_mar
04-26-2006, 11:09 PM
yes you should get a new book as the error in there is quite dumb (unless it's not the full code).
mysql_connect() doesn't return an object.
The closest thing I'd to it would be the use of the mysqli extension which is object oriented.

Lyconpire
04-26-2006, 11:29 PM
yes you should get a new book as the error in there is quite dumb (unless it's not the full code).
mysql_connect() doesn't return an object.
The closest thing I'd to it would be the use of the mysqli extension which is object oriented.

right i understand that ok i tried mysqli and got this error now.

Fatal error: Call to undefined function: mysqli() in auth.php on line 10

$db_conn = mysqli
('localhost', '******', '******', '******');


Running MySQL version 4.0.25-standard

i just seem to be albe to bring the errors out of php....:cool:

ralph l mayo
04-26-2006, 11:32 PM
Objects are created with the new keyword, try $db_host = new mysqli('stuff');

Lyconpire
04-26-2006, 11:39 PM
yeh hehe i seen that in google guess what i now get this...

Fatal error: Cannot instantiate non-existent class: mysqli in auth.php on line 10


$db_conn = new mysqli
('localhost', '******', '******', '*****');

Lyconpire
04-26-2006, 11:43 PM
yeh hehe i seen that in google guess what i now get this...

Fatal error: Cannot instantiate non-existent class: mysqli in auth.php on line 10


$db_conn = new mysqli
('localhost', '******', '******', '*****');


ooo google says i need php5 i will call my host tomorrow:rolleyes:

marek_mar
04-27-2006, 12:36 AM
Objects are created with the new keyword, try $db_host = new mysqli('stuff');
That keyword is called an operator :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum