Switch from MYSQl to MYSQLi

After a PHP upgrade MYSQL will no longer work without displaying errors so many webmasters are being forced to switch to MYSQLi. This can be a scary and daunting task but once you get into it the job moves along at quite a pace.

The basis is quite simply a small change in code:

With MYSQL you may have something like this:

With MYSQLi you would end up with this;

The only difference is the inclusion of the 'i' wherever you have mysql. (This can easily be done with Find and Replace)

Add the $database to $connection you then no longer need the line beginning $db = mysql_select_db

Split the line

$result = mysql_query("SELECT * FROM table") or die(mysql_error());

Giving:

$query = "SELECT * FROM table";
$result = mysqli_query($connection,$query);

Of course PHP and mysql is a complex and wide ranging subject but I hope that this shows you that convertion is not that difficult to do.


Accept Cookies?