Skip to content

Upgrading from mysql_connect() to mysqli_connect()

It’s pretty smooth to upgrade from the old mysql to the new mysqli functions in PHP. Most of them are the same, and documented well on the php.net website.

However if you’re clients have configured database server names back in mysql_connect() days then they may have added the port number or socket to the mysql hostname like this:

my-database-server.com:3306

my-database-server.com:/tmp/socket5

When these are passed into your new updated mysqli_connect() call they will not work. You have to specify these port/socket arguments separately.

Here’s a basic script to split them out and support those who have setup their scripts prior to mysqli_connect() days:

Published inWeb Development

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

© dtbaker.net