Page 1 of 1

Worth updating my scripts to use mysqli?

Posted: Sat Mar 03, 2007 12:13 pm
by seodevhead
Hey guys.... I recently upgraded my PHP on my local and production server from 4.4.3 -> 5.2.1. For the sake of staying modern, it would be nice to update all my code to reflect the new mysqli extension as opposed to all the code I've written with the standard mysql functions (ie. mysqli_connect() compared to mysql_connect(), etc.).

Do you think it would be worth my time to go through about 100 php files and update the existing mysql functions to reflect the newer mysqli? Or is it a waste of time and should I just be happy with my current mysql extension configuration and continue using that. (From what I am reading, you 'shouldn't' have both mysql and mysqli extensions uncommented in php.ini).

Thought I would hear some thoughts. Thanks for your guidance.

Posted: Sat Mar 03, 2007 12:16 pm
by feyd
I would say time is better spent elsewhere, but if you think updating is important.. I would switch away from calling the functionality directly, shifting toward an encapsulated interaction via a class or even set of user-defined functions. Either way, further alterations will often become easier as there would only be this one central location to change for many things.

Posted: Sat Mar 03, 2007 12:25 pm
by seodevhead
Thanks for the advice feyd. So you are suggesting making any mysql function (ex. mysql(i)_query()) a part of a class that is external to all my scripts... so that anytime I need to update a mysql function, I only have to change one file... correct?

Even with that being duly noted... should I continue creating applications using the mysql extension (as opposed to mysqli)? I've been looking in the php manuals and don't see anything about it being deprecated.. am I right?

Posted: Sat Mar 03, 2007 12:35 pm
by feyd
MySQLi is a different way of producing the same general connection. It, internally, has a more up to day, by default, library to interface with MySQL with.. however updating the library the original API uses to the newer version provided by MySQL almost entirely nullifies the differences.

There are a few features MySQLi supports over the MySQL extension such as a multiple query function.

Posted: Sat Mar 03, 2007 12:39 pm
by seodevhead
feyd wrote:..however updating the library the original API uses to the newer version provided by MySQL almost entirely nullifies the differences.
So there is a way of updating the old mysql extension so that it more 'up to snuff'? Where could I find information on how to do this? Thanks feyd!

Posted: Sat Mar 03, 2007 12:41 pm
by RobertGonzalez
If you plan on using any of the MySQL 5 advanced features (stored procs, triggers, views) you are going to want MySQLi. You might also want it if you are planning to use prepared statements in MySQL 4.1. If you want to stay in the dark ages of MySQL 3.23, the keep using mysql. :wink:

Posted: Sat Mar 03, 2007 12:50 pm
by feyd
http://dev.mysql.com/downloads/connector/php/

The old library can be updated to work with the new connection requirements for MySQL 5. ;)

Posted: Sat Mar 03, 2007 6:33 pm
by seodevhead
Thanks so much for your help feyd & everah. I think I'm going to bite the bullet and spend tomorrow morning updating to mysqli functions. I am still learning OOP php5, so another day or two before I feel comfortable enough moving over to a database connection class. Thanks again.