wafflestomper Posted April 14, 2007 Share Posted April 14, 2007 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 More sharing options...
Glyde Posted April 14, 2007 Share Posted April 14, 2007 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. Link to comment https://forums.phpfreaks.com/topic/46955-mysql-connection-differences/#findComment-228961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.