PHP Classes

Moving from MySQL to MySQLi

Recommend this page to a friend!

      PHP Classes blog  >  Are You Ready for MyS...  >  All threads  >  Moving from MySQL to MySQLi  >  (Un) Subscribe thread alerts  
Subject:Moving from MySQL to MySQLi
Summary:It is not as difficult as it may first sound
Messages:5
Author:Dave Smith
Date:2015-05-18 06:15:24
Update:2015-05-18 06:38:09
 

  1. Moving from MySQL to MySQLi   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2015-05-18 06:19:07
I have already moved most of my code over to MySQLi from MySQL and it isn't that difficult.

The biggest change is that MySQL did not require the link identifier, it just used the last connection if it wasn't supplied. MySQLi in procedural mode requires the object which represents the connection. PHP has provided aliases for the MySQLi methods in procedural mode, so you change your mysql_connect to mysqli_connect and add the object identifier to the statements that require it, which are the ones that do not already reference a resource.

Dave

  2. Re: Moving from MySQL to MySQLi   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-05-18 06:22:57 - In reply to message 1 from Dave Smith
Yes, it is not too hard, but if you have a legacy project with mysql extension calls in many places, it may still be a lot of work and things may break due to the differences.

It would be easier if people have used a database wrapper or an abstraction layer, but many developers never thought of that when they did it.

Anyway, the mysql extension will still be available as PECL extension for those that can control their PHP distribution like in dedicated or virtual servers. That may not be the case of those in shared hosting plans.

  3. Re: Moving from MySQL to MySQLi   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2015-05-18 06:27:46 - In reply to message 2 from Manuel Lemos
Don't forget, there is a deprecated functions checker that points you right to the file and line number that needs changing, it is being voted on this month in the innovation awards. (shameless plug) ):

  4. Re: Moving from MySQL to MySQLi   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2015-05-18 06:28:41 - In reply to message 3 from Dave Smith
hahaha, you just forgot to link to that package page! :-)

  5. Re: Moving from MySQL to MySQLi   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2015-05-18 06:38:09 - In reply to message 4 from Manuel Lemos
PHP Deprecated functions checker can be found here...

phpclasses.org/depcheck

btw... that was supposed to be a smiley at the end of my last post, but somehow I wound up with a uni-brow.