I've been able to execute multiple prepared statements using mysqli (in PHP).
However, for some reason the prepared statements always encounter an error when I try running a "SELECT" command.
For example, the following line will succeed:
$stmt=$mysqli->prepare("UPDATE events SET category='m' WHERE id=(?)");
However, the following line will fail:
$stmt=$mysqli->prepare("SELECT * FROM events WHERE id=(?)");
When I say fail, I mean that the next three lines will return 1 for the UPDATE command (indicating that one row was changed)...
$stmt->bind_param('i',$id);
$stmt->execute();
echo $stmt->affected_rows;
The next three lines will return 0 for SELECT:
$stmt->bind_param('i',$id);
$stmt->execute();
echo $stmt->num_rows;
For the record, I'm aware that prepared statements aren't that efficient for a single SELECT - this question is mostly academic.
No comments:
Post a Comment