0

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.

Ricardo Raz
  • 493
  • 1
  • 10
  • 23

1 Answers1

1

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;
Ahmed Alaa El-Din
  • 1,813
  • 1
  • 16
  • 19