即使数据存在,Prepared Statement也不返回行[重复]

This question already has an answer here:

Hello how should I make this work:

I am wondering why when I'm using a prepared statement it doesn't work. I tried using the query method and it works.

Here's what I've tried:

$query = new mysqli('localhost','root', '', 'sample');

$rows = $query->query('SELECT * FROM `sample`.`sample_user` WHERE `userName` = "test" AND `userPass` = "data"');
echo $rows->num_rows; // this returns 1 since I have this record from my database

I'm trying to enhanced it by using a prepared statement :

$query = new mysqli('localhost','root', '', 'sample');
$prepared = $query->prepare('SELECT * FROM `sample`.`sample_user` WHERE `userName` = ? AND `userPass` = ?');

$prepared->bind_param("ss", $userName, $userPass );
$prepared->execute();
echo $prepared->num_rows; //this returns 0

I'm stuck with this issue. Maybe there's something I missed.

</div>

Yeah you need to return the results, binding just bind the query to the params you provide.

 /* Get the result */
 $result = $stmt->get_result();

 /* Get the number of rows */
 $num_of_rows = $result->num_rows;