php mysqli 和 mysql 的区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5641752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:03:27  来源:igfitidea点击:

Difference between mysqli and mysql?

phpmysqlmysqli

提问by Basic

Possible Duplicate:
Advantages Of MySQLi over MySQL

可能的重复:
MySQLi 相对于 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?

我现在正在清理我的值并为安全性转义字符,但我想知道这些 mysql 查询在 php 中的不同好处?

Thanks.

谢谢。

回答by ceejayoz

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

在较旧的 MySQL 函数上使用 MySQLi。“i”代表“改进”。可以在文档中找到改进列表。

回答by Lior Cohen

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.

为什么不改用 PDO?您可以在那里的其他功能中受益于准备好的语句,如果有一天您决定转移到另一个数据库,这将被证明是一个明智的决定。

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

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.

如果您坚持使用上述选项之一,MySQLi 基本上是标准 mysql 扩展的一种更面向对象的方法。在大多数情况下,它们在功能方面是相同的。如果您正在构建基于 OOP 的应用程序,MySQLi 可能是一个更明智、更一致的选择。

回答by gd1

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.

首先,您最好在您的代码和 PHP 提供的数据库函数之间使用 PDO(如 Lior 建议的)或中间层(由您编码),以便您可以轻松地使用 mysqli 或任何您喜欢的方式更改 mysql,而无需重新编辑你的整个代码。

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

至于区别,mysqli 有更多的功能(有一堆新功能)并且也是面向对象的。

回答by a1ex07

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 outparameters or which return resultset.

在我看来,主要区别(改进)是 mysqli 允许您执行多个查询;这反过来又允许您执行(并从中检索结果)带有out参数或返回结果集的存储过程。

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

我确实同意其他人的看法,即使用 PDO 是更好的选择。

回答by Brad Sparks

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.

对于所有说要使用 PDO 的人。仅用于准备好的语句吗?因为您可以在没有 PDO 的情况下在 mySQLi 中执行准备好的语句。仅供参考。