Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between mysqli_connect and mysql_connect?

Tags:

php

mysql

What is the difference between mysqli_connect and 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?

like image 233
locoboy Avatar asked Jun 17 '11 18:06

locoboy


People also ask

What is mysqli_connect?

The mysqli_connect() function establishes a connection with MySQL server and returns the connection as an object.

What is the difference between New MySQLi and mysqli_connect?

I just found a subtle but interesting difference between the two. If you encounter a connection error with mysqli_connect (like $connection = mysqli_connect() ), no mysql info will be returned to the $connection variable. As such, you will not be able to identify the error with myqli_errno($connection) .

Why is mysql_connect () used?

Definition and Usage. The mysql_connect() function opens a non-persistent MySQL connection. This function returns the connection on success, or FALSE and an error on failure. You can hide the error output by adding an '@' in front of the function name.

What is the difference between MySQL Connect and MySQL P connect?

Mysql_connect() opens a new connection to the database while mysql_pconnect() opens a persistent connection to the database. This means that each time the page is loaded mysql_pconnect() does not open the database.


2 Answers

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.

like image 144
Francois Deschenes Avatar answered Sep 21 '22 12:09

Francois Deschenes


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

They are not interchangeable.

like image 20
alex Avatar answered Sep 20 '22 12:09

alex