Page 1 of 1
mysqli problem in fetching
Posted: Thu Sep 27, 2007 11:33 am
by itsmani1
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
Posted: Thu Sep 27, 2007 11:39 am
by feyd
It obviously didn't return an object. I suspect the query failed.
Posted: Thu Sep 27, 2007 12:08 pm
by itsmani1
if i try on command line of mysql like:
it gives me correct result.
Posted: Thu Sep 27, 2007 12:17 pm
by volka
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.
Posted: Thu Sep 27, 2007 12:40 pm
by olog-hai
Posted: Thu Sep 27, 2007 1:05 pm
by itsmani1
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;
Posted: Thu Sep 27, 2007 1:09 pm
by olog-hai
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
Posted: Thu Sep 27, 2007 2:35 pm
by volka
Take a look at
http://de2.php.net/mysqli_error , Example 1472.
if (!$mysqli->query("SET a=1")) {
printf("Errormessage: %s\n", $mysqli->error);
}