Page 1 of 1

Mysqli help

Posted: Wed May 19, 2010 11:14 am
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.

Re: Mysqli help

Posted: Wed May 19, 2010 11:18 am
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

Re: Mysqli help

Posted: Wed May 19, 2010 11:25 am
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.