which mysql library should i use in php and why
I have been using php for quite a sometime now and encounter three different interfaces viz. mysql_*, mysqli_* and PDO
to connecting with mysql database. What i am not able to understand is why to have so many interfac开发者_开发技巧es for the same.. if one is better then which one?? or is it a matter of choice between select one or other. Does there exists any difference in performance and speed with each of the interfaces?
While mysql (procedural) and mysqli (OO) are MySQL client libraries, PDO is a data-access abstraction layer, it allows you to use different database drivers. An advantage of PDO is you could, theorically, change your database driver without rewriting your querying code.
I recommend you to check http://php.net/manual/en/mysqli.overview.php where differences between those 3 libraries are briefly discussed.
The MySQLi extension is a new & improved (hence the i) database driver, compared to MySQL. With MySQLi you can take advantage of features such as prepared statements, as well as what fcingolani has said.
PDO is a data-access abstraction layer, which have many drivers such as MsSQL, MySQL and PostgreSQL.
If you're going really only with MySQL you should go with MySQLi
as it's specific to MySQL and faster that the regular MySQL
. If you're doing MySQL now but may be doing Postgree or any database in the future PDO abstracts your database logic from the actual database so should be your choice.
MySQLi is slightly faster on some operations that PDO.
精彩评论