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
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Sep 27, 2007 11:33 am
Code: Select all
<?php
$mysqli = connection1();
$category = "call category(0)";
$query =$mysqli->query($category);
while($data = $query->fetch_row()) {
echo "<option value=".$data[0].">".$data[1]."</option>";
}
$mysqli->close();
?>
I am getting following error when i try to run above code, connection is ok there is no problem to it.
<b>Fatal error</b>: Call to a member function fetch_row() on a non-object in <b>/home/cmela/public_html/includes/header_index.php</b> on line <b>48</b><br />
my Client API library version: 4.1.21
Please help me
thank you
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Sep 27, 2007 11:39 am
It obviously didn't return an object. I suspect the query failed.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Sep 27, 2007 12:08 pm
if i try on command line of mysql like:
it gives me correct result.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Sep 27, 2007 12:17 pm
And the script doesn't. That's why you
always need error handling in your script.
Take a look at
http://de2.php.net/mysqli_error , Example 1472.
olog-hai
Forum Commoner
Posts: 34 Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada
Post
by olog-hai » Thu Sep 27, 2007 12:40 pm
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Sep 27, 2007 1:05 pm
this is no problem with connection because following gives me:
I think problem is with version
Output:
issue
Code: Select all
if(mysqli_connect_errno()) die ("Error connecting MySQL: ".mysqli_connect_error());
$category = "call category(0)";
if($query =$mysqli->query($category))
{
echo 'yes';
}
else
{
echo 'issue';
}
exit;
olog-hai
Forum Commoner
Posts: 34 Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada
Post
by olog-hai » Thu Sep 27, 2007 1:09 pm
You use mysqli like an instance where is your declaration ?
like myobj = new mysqli ( host, user, pwd , database)
else if you use procedural mode, you have to use mysqli_query($sql,$connection);
don't mix both in your code
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Sep 27, 2007 2:35 pm
Take a look at
http://de2.php.net/mysqli_error , Example 1472.
if (!$mysqli->query("SET a=1")) {
printf("Errormessage: %s\n", $mysqli->error );
}