Why doesn't MySQLi library natively support named parameters?

前端 未结 2 1174
庸人自扰
庸人自扰 2021-02-19 07:54

Proper MySQLi parameterized query syntax from http://php.net/manual/en/mysqli.quickstart.prepared-statements.php:

$stmt = $mysqli->prepare(\"INSERT INTO test(         


        
2条回答
  •  醉酒成梦
    2021-02-19 08:38

    MySQLi, traditionally, is a very thin wrapper for the MySQL API. It doesn't add anything on its own and for a reason: adding such features as named placeholders will require, if you think of it, a whole leviathan of SQL query parsing. Definitely, it is not a job for a database API. Like it is said in the other answer, API is not a DAL or DBAL; they serve for different purposes.

    PDO was a great feat you hardly would see again in the language and Wes Furlong is a genius who undertook the task almost single-handedly. But again, PDO is a different story. It's a database access abstraction layer, and to achieve this goal you need a query parser, like it or not. And as you already have a query parser and one of drivers already supports named placeholders, it would be natural to add it to all supported drivers. As you can see, with MySQLi it is all different.

    To put it short, it is not about "laziness"; it is about following the specification.

提交回复
热议问题