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?
The mysqli_connect() function establishes a connection with MySQL server and returns the connection as an object.
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) .
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With