I have a simple prepared statement for an email that actually exists:
$mysqli = new mysqli("localhost", "root", "", "test");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql = 'SELECT `email` FROM `users` WHERE `email` = ?';
$email = 'example@hotmail.com';
if ($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param('s', $email);
$stmt->execute();
if ($stmt->num_rows) {
echo 'hello';
}
echo 'No user';
}
Result: echos No user
when it should echo hello
I ran the same query in the console and got a result using same email as above.
I tested using a simple mysqli query as well:
if ($result = $mysqli->query("SELECT email FROM users WHERE email = 'example@hotmail.com'")) {
echo 'hello';
}
Result: what I expected hello
Also $result
's num_rows
is 1.
Why is the prepared statment's num_row
not greater than 0?