Difference between mysqli and mysql? [duplicate]

2019-02-05 05:40发布

问题:

Possible Duplicate:
Advantages Of MySQLi over MySQL

I am building a large database and wondered which is the best to use?

I am sanitizing my values now and escaping characters for security but I would like to know the different benefits of these mysql querys in php?

Thanks.

回答1:

Use MySQLi over the older MySQL functions. The "i" stands for "improved". The list of improvements can be found in the docs.



回答2:

First of all, you better use PDO (as Lior suggested) or an intermediate layer (coded by you) between your code and the database functions provided by PHP, so that you can easily change mysql with mysqli or whatever your like without re-editing your whole code.

As of the differences, mysqli has more functionalities (there are a bunch of new functions) and is also object-oriented.



回答3:

Why not use PDO instead? You have the benefit of prepared statements amongst other features there and it would prove to be a wise decision should you decide to move to another DB one day.

http://php.net/manual/en/book.pdo.php

If you insist on using one of the options mentioned above, MySQLi is basically a more Object Oriented approach to the standard mysql extension. For the most part, they are functionality-wise the same. If you're building an OOP based application, MySQLi would probably be a wiser, more consistent choice.



回答4:

From my point of view, the main difference (improvement) is that mysqli lets you execute multiple queries; that in turn allows you to execute (and retrieve results from) stored procedures with out parameters or which return resultset.

I do agree with others that using PDO is a better choice though.



回答5:

For all those saying to use PDO. Is it only for the prepared statements? Because you can do prepared statements in mySQLi without PDO. Just FYI.



标签: php mysql mysqli