Why doesn't the MySQLi library support named parameters?

The corresponding MySQLi syntax syntax with the parameter http://php.net/manual/en/mysqli.quickstart.prepared-statements.php :

$stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)"); $stmt->bind_param("i", $id); 

But never like that:

 $stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (:id_value)"); $stmt->bind_param("i", "id_value", $id); 

It seems to me that named parameter substitution is a reasonable function, implemented at the API level. I am surprised that MySQLi only implemented unnamed parameters in the library.

Is there a good reason? For me this does not make sense, because all PDO, DQL, ORM still accepted named parameters in their queries.

I hope this was not the case: "We were lazy and do not want" from the MySQLi developers. I believe that there must have been a good reason, and I am looking for this reason or a way to find this reason. The reason that named parameters are not implemented in the MySQLi extension library.

+10
php mysqli named-parameters
source share
3 answers

MYSQLi does not support named parameters for two main reasons:

  1. It is โ€œintendedโ€ (I use this term freely) for use with the wrapper and
  2. It makes an analogue of PDO - and it makes no sense to reinvent the wheel

To clarify point 1: mysqli , despite numerous shortcomings compared to PDO , becomes easily comparable to a good wrapper, that is, named parameters (among others) are supported by the wrapper, and not by TG44 itself. This is done for one single reason:

  1. Mysqli designed for a fast and flexible library.

If developers embed a lot more functions in the base library, it becomes more intuitive, less flexible, and takes longer to load / execute.

Both mysqli and pdo were released with PHP 5 (I think PDO with version 5.3) and are therefore designed for various purposes.

Do you want faster lead time? use mysqli without shell. Do you want named parameters? use a PDO or create a mysqli wrapper for such processing - but be careful, this will interfere with your runtime.

0
source share

MySQLi has traditionally been a very thin shell for the MySQL API . It does not add anything by itself and for a reason: adding functions such as named placeholders will require, if you think, a whole leviathan to parse SQL queries. Definitely, this is not a job for the database API. As another answer says, an API is not a DAL; they serve for different purposes.

PDO was a great feat that you are unlikely to see again in that language, and Wes Farlong is a genius who accomplished the task almost arrogantly. But then again, PDO is a different story. This is the abstraction level of access to the database, and to achieve this you need a query analyzer whether you like it or not. And since you already have a query analyzer and one of the drivers already supports named placeholders, it would be natural to add it to all supported drivers. As you can see, things are different with MySQLi.

In short, this is not about "laziness"; it is about following the specification.

+1
source share

The reason for this is quite simple: they are not lazy, and they probably would like to have this function, but for them it may not be possible, but : may already be something already.

Although, I would strongly suggest not using MySQLI and switching to PDO, because it is simpler, and it is easier for people like me and you to understand.

0
source share

All Articles