mysqli problem in fetching

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

mysqli problem in fetching

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It obviously didn't return an object. I suspect the query failed.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

if i try on command line of mysql like:

Code: Select all

call category(0);
it gives me correct result.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
olog-hai
Forum Commoner
Posts: 34
Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada

Post by olog-hai »

try to use multi_query with Stored Procedure

http://ca.php.net/manual/fr/function.my ... -query.php
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post 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;
User avatar
olog-hai
Forum Commoner
Posts: 34
Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
}
Post Reply