Why doesn't MySQLi library natively support named parameters?

前端 未结 2 1163
庸人自扰
庸人自扰 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:27

    MYSQLi doesn't support named parameters for two main reasons:

    1. It is "intended" (I use this term loosely) to be used with a wrapper and
    2. It's counterpart, PDO, does - and there is no point re-inventing the wheel

    To elaborate on point 1: mysqli, despite its many downfalls when compared to PDO, becomes easily comparable with a good wrapper - that is, named parameters (among others) are supported by the wrapper rather than mysqli itself. This is by design for one sole reason:

    1. Mysqli is designed to be a fast and flexible library.

    If the developers incorporated many more features into the base library, it becomes, counter intuitively, less flexible and requires longer load/execution times.

    Both mysqli and pdo were released with PHP 5 (PDO with version 5.3, I believe) and as such are intended for different uses.

    You want faster execution times? use mysqli without a wrapper. You want named parameters? use PDO or build a mysqli wrapper to handle such - but be warned, this will hinder your execution times.

提交回复
热议问题