php mysqli_connect 和 mysql_connect 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6390102/
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-26 00:13:21  来源:igfitidea点击:

What is the difference between mysqli_connect and mysql_connect?

phpmysql

提问by locoboy

What is the difference between mysqli_connect and mysql_connect?

mysqli_connect 和 mysql_connect 有什么区别?

I'm just wondering when I should use which one. I see both being used, and it seems like they are interchangable.

我只是想知道什么时候应该使用哪个。我看到两者都在使用,而且它们似乎可以互换。

Which connection is better and how are they fundamentally different when connecting?

哪种连接更好,它们在连接时有何根本不同?

采纳答案by Francois Deschenes

They're not interchangeable. There are different extensions to access MySQL databases.

它们不可互换。有不同的扩展可以访问 MySQL 数据库。

See http://ca2.php.net/manual/en/book.mysqli.phpand http://ca2.php.net/manual/en/book.mysql.php.

请参阅http://ca2.php.net/manual/en/book.mysqli.phphttp://ca2.php.net/manual/en/book.mysql.php

回答by alex

mysqli_*()is the modern way to access a MySQL database via PHP.

mysqli_*()是通过 PHP 访问 MySQL 数据库的现代方式。

They are notinterchangeable.

它们不可互换。

回答by Chris Baker

Check out the documentation: http://ca3.php.net/manual/en/mysqli.overview.php

查看文档:http: //ca3.php.net/manual/en/mysqli.overview.php

From the section "What is PHP's mysqli Extension?"

来自“什么是 PHP 的 mysqli 扩展?”部分。

The mysqli extension, or as it is sometimes known, the MySQL improved extension, was developed to take advantage of new features found in MySQL systems versions 4.1.3 and newer. The mysqli extension is included with PHP versions 5 and later.

mysqli 扩展,或者有时称为 MySQL 改进的扩展,是为了利用 MySQL 系统版本 4.1.3 和更新版本中的新功能而开发的。mysqli 扩展包含在 PHP 5 及更高版本中。

There are several important differences between the two libraries:

这两个库之间有几个重要的区别:

  • Mysqli supports supports charsets, mysql does not
  • Mysqli supports prepared statements, mysql does not
  • Mysql does not support multiple statements, mysqli does
  • mysqli 支持支持字符集,mysql 不支持
  • mysqli 支持预处理语句,mysql 不支持
  • Mysql 不支持多语句,mysqli 支持

回答by fholzer

MySQL and MySQLi are two separate PHP extensions, MySQLi being the newer one. Although the connect functions maybe interchangeable, I would disadvise to do so!

MySQL 和 MySQLi 是两个独立的 PHP 扩展,MySQLi 是较新的一个。尽管连接功能可以互换,但我不建议这样做!

MySQLi provides a object-oriented way for accessing MySQL databases.

MySQLi 提供了一种面向对象的方式来访问 MySQL 数据库。

in short: if you use mysql_query(), you should use mysql_connect() to connect to your server.

简而言之:如果您使用 mysql_query(),您应该使用 mysql_connect() 连接到您的服务器。

Others already postet links to the PHP manual.

其他人已经发布了指向 PHP 手册的链接。

回答by Ganesh Hargude

Mysqli_connect is the newer version of mysql library.

mysqli_connect 是较新版本的 mysql 库。

Here I in mysqli stands for improved.

这里我在mysqli中代表改进。

Few things have been introduced with Mysqli.

Mysqli 引入的东西很少。

They are,

他们是,

-Prepared statements.

- 准备好的陈述。

-Object oriented interface.

- 面向对象的界面。

-Support for multiple statements.

- 支持多语句。

-Embedded server support.

- 嵌入式服务器支持。

The mysqli extension has a number of benefits, the key enhancements over the mysql extension being:

mysqli 扩展有很多好处,对 mysql 扩展的主要增强是:

-Object-oriented interface

- 面向对象的接口

-Support for Prepared Statements

- 支持准备好的报表

-Support for Multiple Statements

- 支持多语句

-Support for Transactions

- 支持交易

-Enhanced debugging capabilities

- 增强的调试功能

-Embedded server support

- 嵌入式服务器支持

So Mysql_connect() basically is the database connector to Mysql whereas Mysqli_connect() is the connector for Mysqli databse

所以 Mysql_connect() 基本上是 Mysql 的数据库连接器,而 Mysqli_connect() 是 Mysqli 数据库的连接器