Web Hosting Talk







View Full Version : mysql versus mysqli


innova
01-28-2005, 03:35 PM
Something I have been wondering for awhile...

I have a project I've been messing around with and I would like to implement some of the new features in mysql 4.1.x as opposed to the 4.0.x series.

Now, I have been reading up on mysql/mysqli on the php side of things. One question I havent found the answer to is this:

How can one support both versions? Lets say I want to support mysql 4.0.x and gradually move to 4.1.x and incorporate new functionality. Of course, eventually 4.1.x will be the norm.

Is there a good way to handle this?

hiryuu
01-28-2005, 05:02 PM
This is one of those times where it helps to have a library or object handling the back end, rather than having your apps use the functions directly. That will be a very difficult transition if you have your mysql_* functions strewn across dozens of scripts.

innova
01-28-2005, 06:59 PM
Very true.

I might look into Pear::DB or adodb (not sure offhand if they support both mysql extensions now).

I noticed that phpmyadmin uses a variable to set whether it uses mysql or mysqli.

Rich2k
01-28-2005, 07:02 PM
You can do this.

Basically to use the mysql extensions with a MySQL 4.1 database or better you must set up the user with the OLD_PASSWORD() function and then they will work. When you are ready to use the mysqli functions then just create a new user properly and use that instead.

We do what innova says and in a similar way to phpMyAdmin we have a configuration option to select from mysql or mysqli and you just store the relevant database functions in their own classes.

Burhan
01-29-2005, 03:40 AM
You can also load the module dynamically if your PHP version has that support enabled. That way, you only use mysqli* when its needed.