Worth updating my scripts to use mysqli?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Worth updating my scripts to use mysqli?

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post 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!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. ;)
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post 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.
Post Reply