什么时候应该使用MySQLi而不是MySQL?

时间:2023-02-07 16:07:28

Can someone clarify for me what the advantages and disadvantages of using MySQLi instead of MySQL? Are there situations where I should not use MySQLi? Do I need to configure my server differently in order to use MySQLi? For instance, do I need to upgrade Apache or PHP so I can support MySQLi?

谁能给我解释一下使用MySQLi而不是MySQL的优点和缺点吗?是否存在不使用MySQLi的情况?为了使用MySQLi,是否需要对服务器进行不同的配置?例如,我是否需要升级Apache或PHP以支持MySQLi?

5 个解决方案

#1


34  

Reasons why you should use MySQLi extension instead of the MySQL extension are many:

使用MySQLi扩展而不是MySQL扩展的原因有很多:

  1. MySQLi gives you prepared statements - a safer way of sending data to MySQL and protecting you from SQL injection. This alone should be enough for always choosing MySQLi over MySQL.
  2. MySQLi为您提供了准备好的语句——一种将数据发送到MySQL并保护您不受SQL注入影响的更安全的方法。单凭这一点就足以让我选择MySQLi而不是MySQL。
  3. MySQLi enables most of the MySQL features.
  4. MySQLi支持大多数MySQL特性。
  5. MySQLi is object orientated.
  6. MySQLi是面向对象的。
  7. MySQLi supports prepared statements, transactions and multiple statements.
  8. MySQLi支持准备语句、事务和多个语句。
  9. The old MySQL extension is deprecated as of PHP 5.5.0
  10. 旧的MySQL扩展在PHP 5.5.0中已经过时了

And there are other benefits. But mainly, you should focus on security and stabiltity - and MySQLi gives you just that.

还有其他的好处。但主要的是,您应该关注安全性和稳定性——MySQLi提供了这一点。

#2


8  

PHP team refuse to support mysql extension any further. This reason is alone enough.

PHP团队拒绝进一步支持mysql扩展。这个理由就足够了。

All other reasons don't make much sense:

所有其他原因都没有多大意义:

  • MySQLi gives you prepared statements - one can use old mysql with manually handled plaeholders and get even safer. This alone should be stopping MySQL from useless deprecation.
  • MySQLi提供了准备好的语句——可以使用老的mysql手动处理的plae持有者,并且变得更加安全。单是这一点就应该阻止MySQL无用的弃用。
  • MySQLi enables most of the MySQL features which most of PHP users never ever heard of.
  • MySQLi支持大多数PHP用户从未听说过的MySQL特性。
  • MySQLi is object oriented - a pair of straight hands can make old mysql objec oriented in a matter of several hours.
  • MySQLi是面向对象的——一双直来直去的手可以在几个小时内使旧的mysql objec定向。
  • *MySQLi supports
    • transactions* - mysql supports them as well. just run START TRANSACTION query and you're set.
    • 事务* - mysql也支持它们。只要运行START事务查询,就设置好了。
    • multiple statements - yet nobody actually needs them.
    • 多个语句——但是实际上没有人需要它们。
    • prepared statements - as a matter of fact, the support is horrible, renders them practiaclly unusable
    • 准备好的陈述-事实上,支持是可怕的,使他们在实践中无法使用。
  • MySQLi支持事务* - mysql也支持事务。只需运行START事务查询,您就可以看到多个语句——但实际上没有人需要它们。准备好的陈述-事实上,支持是可怕的,使他们在实践中无法使用。

So, there are no advantages at all.
If you want to get along with non-deprecated but usable extension - go for the PDO.

所以,没有任何优势。如果您想与非弃用但可用的扩展一起使用,请选择PDO。

#3


4  

If you are using mysql > 4.1.3. Mysqli is a new interface for mysql in php. A quote from http://www.php.net/manual/en/mysqli.overview.php

如果您正在使用mysql > 4.1.3。Mysqli是php中mysql的一个新接口。引用http://www.php.net/manual/en/mysqli.overview.php

What is PHP's MySQL Extension?

This is the original extension designed to allow you to develop PHP applications that interact with a MySQL database. The mysql extension provides a procedural interface and is intended for use only with MySQL versions older than 4.1.3. This extension can be used with versions of MySQL 4.1.3 or newer, but not all of the latest MySQL server features will be available.

这是最初设计的扩展,用于开发与MySQL数据库交互的PHP应用程序。mysql扩展提供了一个过程接口,只适用于4.1.3以上的mysql版本。这个扩展可以与MySQL 4.1.3或更新版本一起使用,但并不是所有最新的MySQL服务器特性都可用。

Note:

If you are using MySQL versions 4.1.3 or later it is strongly recommended that you 
use the mysqli extension instead.

#4


2  

Always, if possible.

总是这样,如果可能的话。

It is possible that MySQLi is not supported by your PHP install. However, most hosting providers have support for MySQLi.

您的PHP安装可能不支持MySQLi。然而,大多数主机提供商都支持MySQLi。

#5


0  

Unless you are using an old version of the MySQL database (prior to 4.1.3) or require some functionality not yet included in MySQLi (I think there are one of two functions that weren't moved over) then stick with MySQLi when ever you can.

除非您使用的是旧版本的MySQL数据库(4.1.3之前),或者需要MySQLi中尚未包含的一些功能(我认为有两个功能中有一个是没有移动的),否则在任何时候都要使用MySQLi。

#1


34  

Reasons why you should use MySQLi extension instead of the MySQL extension are many:

使用MySQLi扩展而不是MySQL扩展的原因有很多:

  1. MySQLi gives you prepared statements - a safer way of sending data to MySQL and protecting you from SQL injection. This alone should be enough for always choosing MySQLi over MySQL.
  2. MySQLi为您提供了准备好的语句——一种将数据发送到MySQL并保护您不受SQL注入影响的更安全的方法。单凭这一点就足以让我选择MySQLi而不是MySQL。
  3. MySQLi enables most of the MySQL features.
  4. MySQLi支持大多数MySQL特性。
  5. MySQLi is object orientated.
  6. MySQLi是面向对象的。
  7. MySQLi supports prepared statements, transactions and multiple statements.
  8. MySQLi支持准备语句、事务和多个语句。
  9. The old MySQL extension is deprecated as of PHP 5.5.0
  10. 旧的MySQL扩展在PHP 5.5.0中已经过时了

And there are other benefits. But mainly, you should focus on security and stabiltity - and MySQLi gives you just that.

还有其他的好处。但主要的是,您应该关注安全性和稳定性——MySQLi提供了这一点。

#2


8  

PHP team refuse to support mysql extension any further. This reason is alone enough.

PHP团队拒绝进一步支持mysql扩展。这个理由就足够了。

All other reasons don't make much sense:

所有其他原因都没有多大意义:

  • MySQLi gives you prepared statements - one can use old mysql with manually handled plaeholders and get even safer. This alone should be stopping MySQL from useless deprecation.
  • MySQLi提供了准备好的语句——可以使用老的mysql手动处理的plae持有者,并且变得更加安全。单是这一点就应该阻止MySQL无用的弃用。
  • MySQLi enables most of the MySQL features which most of PHP users never ever heard of.
  • MySQLi支持大多数PHP用户从未听说过的MySQL特性。
  • MySQLi is object oriented - a pair of straight hands can make old mysql objec oriented in a matter of several hours.
  • MySQLi是面向对象的——一双直来直去的手可以在几个小时内使旧的mysql objec定向。
  • *MySQLi supports
    • transactions* - mysql supports them as well. just run START TRANSACTION query and you're set.
    • 事务* - mysql也支持它们。只要运行START事务查询,就设置好了。
    • multiple statements - yet nobody actually needs them.
    • 多个语句——但是实际上没有人需要它们。
    • prepared statements - as a matter of fact, the support is horrible, renders them practiaclly unusable
    • 准备好的陈述-事实上,支持是可怕的,使他们在实践中无法使用。
  • MySQLi支持事务* - mysql也支持事务。只需运行START事务查询,您就可以看到多个语句——但实际上没有人需要它们。准备好的陈述-事实上,支持是可怕的,使他们在实践中无法使用。

So, there are no advantages at all.
If you want to get along with non-deprecated but usable extension - go for the PDO.

所以,没有任何优势。如果您想与非弃用但可用的扩展一起使用,请选择PDO。

#3


4  

If you are using mysql > 4.1.3. Mysqli is a new interface for mysql in php. A quote from http://www.php.net/manual/en/mysqli.overview.php

如果您正在使用mysql > 4.1.3。Mysqli是php中mysql的一个新接口。引用http://www.php.net/manual/en/mysqli.overview.php

What is PHP's MySQL Extension?

This is the original extension designed to allow you to develop PHP applications that interact with a MySQL database. The mysql extension provides a procedural interface and is intended for use only with MySQL versions older than 4.1.3. This extension can be used with versions of MySQL 4.1.3 or newer, but not all of the latest MySQL server features will be available.

这是最初设计的扩展,用于开发与MySQL数据库交互的PHP应用程序。mysql扩展提供了一个过程接口,只适用于4.1.3以上的mysql版本。这个扩展可以与MySQL 4.1.3或更新版本一起使用,但并不是所有最新的MySQL服务器特性都可用。

Note:

If you are using MySQL versions 4.1.3 or later it is strongly recommended that you 
use the mysqli extension instead.

#4


2  

Always, if possible.

总是这样,如果可能的话。

It is possible that MySQLi is not supported by your PHP install. However, most hosting providers have support for MySQLi.

您的PHP安装可能不支持MySQLi。然而,大多数主机提供商都支持MySQLi。

#5


0  

Unless you are using an old version of the MySQL database (prior to 4.1.3) or require some functionality not yet included in MySQLi (I think there are one of two functions that weren't moved over) then stick with MySQLi when ever you can.

除非您使用的是旧版本的MySQL数据库(4.1.3之前),或者需要MySQLi中尚未包含的一些功能(我认为有两个功能中有一个是没有移动的),否则在任何时候都要使用MySQLi。