[php-src] Issue #7903: `mysqli` does not bind params the same way `PDO` does
| From: | kamil-tekiela | Date: | Fri, 07 Jan 2022 15:11:22 +0000 |
| Subject: | [php-src] Issue #7903: `mysqli` does not bind params the same way `PDO` does | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238860@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7903
Comment Author: kamil-tekiela
Unfortunately, there's nothing we can do here. I understand this might be a problem, but from
mysqli perspective, it's not a bug. It works correctly. The real reason why you see a syntax
error is because that SQL has a syntax error... the separator value is not considered to be an
expression, but rather a string value that is part of the SQL itself. It cannot be parameterized,
replaced with a variable or replaced with another data type. It's a strange "feature"
of SQL design. The same way that you can't parameterize column names, you can't
parameterize the separator.
PDO is using emulated prepared by default. The preparation happens on the client-side (PHP) and the
baked SQL query is sent to the server. Because the default parameter binding type is a string, when
the SQL is compiled by PDO, the syntax accidentally comes out right. If you use non-emulated
prepares or if you type-hint the parameter to be an integer, you will also see a syntax error.
In theory, PDO could even allow you to bind column/table names, but it's not possible because
it is using single quotes instead of double quotes (intentionally). When PDO send the query to the
MySQL server, it sends it as a normal SQL query, not a prepared statement. PDO doesn't check
the syntax, it is only performing regex substitution. This means that there's no way for PDO to
inform the user that they can't parameterize
SEPARATOR. It's just a lucky
side-effect of the technology. You can parameterize something that should not be parameterized,
because PDO is too dumb to tell you you can't.
I am going to close this issue as "won't fix" because I don't see anything to
fix here. The mysqli extension is working correctly, and the behaviour of PDO can't and
won't be fixed any time soon. (it's not the only thing that emulated prepares have a
problem with).