Jump to content

MYSQL Connection differences?


wafflestomper

Recommended Posts

What is the difference between connecting to a db this way:

 

<?php
function connect()
{
   $result = new mysqli('localhost', 'username', 'passwd', 'db'); 
   if (!$result)
     throw new Exception('Could not connect to database server');
   else
     return $result;
}
?>

and this way:

<?php
function connect()
{
$con = mysql_connect('localhost', 'username', 'passwd') or die('Could not connect: ' . mysql_error());
mysql_select_db('db') or die('Could not select database');


}
?>

 

 

 

Is one better than another?  Does one always work over the other?

Link to comment
https://forums.phpfreaks.com/topic/46955-mysql-connection-differences/
Share on other sites

They both work just fine, in fact mysql_query tends to run faster than mysqli_query, but MySQLi (MySQL improved) tends to offer better security and functionality.  Additionally, MySQLi introduced many new functions such as prepare.

 

There currently is no big hype to move over to MySQLi, and if you are currently using the standard MySQL, you will notice little difference.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.