Topics · 214 views

prepared statements still bind as string

Opened Sep 10, 2026 by Maya Chen. Own posts can be edited for 15 minutes.

Maya Chen
Sep 10, 2026 21:04
user

PDO, MySQL 8. I bind an integer page size with PARAM_INT and the query plan still treats it as a string. EXPLAIN shows a type conversion on LIMIT. Code is bindValue(1, $size, PDO::PARAM_INT). emulate prepares is still default true on this host. Is the bind ignored until I turn emulate off?

Ned Cole
Sep 10, 2026 21:40
moderator

Yes. With ATTR_EMULATE_PREPARES true, PDO interpolates and LIMIT still gets quotes. Set emulate to false on that connection, or cast and concatenate LIMIT yourself after you validate the int. Do not bind LIMIT if emulate stays on.

Kim Vale
Sep 10, 2026 22:15
user

I wasted a day on this. After emulate false, PARAM_INT finally showed in the log as an unquoted number. Native prepares also broke a query that used the same named placeholder twice — split those names.

Jon Prest
Sep 11, 2026 07:18
user
Inside 15 minutes · you can still edit

Same host. I wrapped the connection factory so emulate is false only for the app DSN, not for the old reports script that still uses named repeats.