I am trying to transition from literal query
calls to prepared statements.
I have the following function in my class:
public function read ($identifier) {
$stmt = static::$mysqli->prepare('SELECT * FROM `table` WHERE `id` = ?;');
$stmt->bind_param('i', $identifier);
$stmt->execute();
var_dump($stmt->num_rows);
}
I know from phpMyAdmin that there is a row with id 1 in the database, but if I call read(1);
, num_rows
is 0.
However, if I use this logic:
public function read ($identifier) {
$result = static::$mysqli->query('SELECT * FROM `table` WHERE `id` = '.(int) $identifier.';');
var_dump($result->num_rows);
}
I get 1 instead.