tags:

views:

93

answers:

1

I'm relatively new to MySQLi prepared statements, and running into an error. Take this code:

$user = 'admin';
$pass = 'admin';

if ($stmt = $mysqli->query("SELECT * FROM members WHERE username='$user' AND     password='$pass'"))
{
echo $stmt->num_rows;
}

This will display "1", as it should.

This next piece of code though, returns "0":

$user = 'admin';
$pass = 'admin';

if ($stmt = $mysqli->prepare("SELECT * FROM members WHERE username=? AND password=?"))
{
$stmt->bind_param("ss", $user, $pass);
$stmt->execute();
echo $stmt->num_rows;
}

Any ideas why?

A: 
Geek Num 88
Thanks, that fixed it.So execute() performs the query, but to access any results from the query I have to use store_result()? I've looked through the PHP MySQLi manual on this and it in't very clear (at least to me =P)
Benjamin Falk
I know, I built an abstraction class around the mysqli object to make prepared statements a heck of alot easier then in the documentation
Geek Num 88
There's another gotcha too - you have to bind the results to a variable, so bind the paramaters, execute, bind the results
Geek Num 88