Mysqli help

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
dhui
Forum Newbie
Posts: 14
Joined: Mon May 10, 2010 1:42 pm

Mysqli help

Post by dhui »

How do I check if a query has returned any results? I tried it below, but can't seem to get it to work as $result->num_rows always returns 0 even when there is data in the result set.

Code: Select all

$sql = "SELECT email, password FROM user WHERE email = '" . $email . "'";

mysqli->query($sql);

$result = mysqli->use_result();

$result->num_rows; //Keeps returning 0 even when there is data.
Thanks.
dhui
Forum Newbie
Posts: 14
Joined: Mon May 10, 2010 1:42 pm

Re: Mysqli help

Post by dhui »

Nevermind, I figured it out.

I have to use store_results instead of use_results to get it to return the correct num_rows
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Mysqli help

Post by flying_circus »

It should be able to be shortened like this:

Code: Select all

$sql = "SELECT email, password FROM user WHERE email = '" . $email . "'";

$result = mysqli->query($sql);

$result->num_rows; //Keeps returning 0 even when there is data.
Post Reply