I started to know how prepared statement works when using MySQLi and PDO, for first step, I enabled MySQL query monitoring as mentioned here: How can I view live MySQL queri
Your PDO is configured to emulate prepared queries, whereas mysqli is using true prepared queries.
The prepared query binds the string ''1''
as an integer parameter value. PHP coerces it to an integer using something like intval()
. Any string with non-numeric leading characters is interpreted as 0 by PHP, so the parameter value sent after prepare is the value 0.
The fake prepared query uses string interpolation (instead of binding) to add the string ''1''
into the SQL query before MySQL parses it. But the result is similar, because SQL also treats a string with non-numeric leading characters in an integer context as the value 0.
The only difference is what ends up in the general query log when the parameter is bound before prepare versus after prepare.
You can also make PDO use real prepared queries, so it should act just like mysqli in this case:
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
PS: This may demonstrate a good reason why it's customary to start id values at 1 instead of 0.