What is the difference between mysqli_connect and mysql_connect?
What is the difference between mysqli_connect and m开发者_JS百科ysql_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?
They're not interchangeable. There are different extensions to access MySQL databases.
See http://ca2.php.net/manual/en/book.mysqli.php and http://ca2.php.net/manual/en/book.mysql.php.
mysqli_*()
is the modern way to access a MySQL database via PHP.
They are not interchangeable.
Check out the documentation: http://ca3.php.net/manual/en/mysqli.overview.php
From the section "What is PHP's mysqli Extension?"
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.
There are several important differences between the two libraries:
- Mysqli supports charsets, mysql does not
- Mysqli supports prepared statements, mysql does not
- Mysql does not support multiple statements, mysqli does
MySQL and MySQLi are two separate PHP extensions, MySQLi being the newer one. Although the connect functions may be interchangeable, I would disadvise to do so!
MySQLi provides a object-oriented way for accessing MySQL databases.
in short: if you use mysql_query(), you should use mysql_connect() to connect to your server.
Others already postet links to the PHP manual.
Mysqli_connect is the newer version of mysql library.
Here I in mysqli stands for improved.
Few things have been introduced with 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:
-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
There are too many differences between these MYSQL and MYSQLi PHP database extensions. These differences are based upon some factors like features, performance, benefits, library functions, security and others. The “i” in mysqli stands for “improved”. The “mysqli” extension is an improvement over the old “mysql” extension.Click here for more information
精彩评论