What is the difference between mysqli_connect and mysql_connect?

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.


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.


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

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

They are not interchangeable.

Tags:

Mysql

Php