Connecting Tech Pros Worldwide Forums | Help | Site Map

Porting to mysqli from mysql

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#1: Jun 17 '09
I am still using the mysql extension rather than the mysqli.
Moving to mysqli would be realively simple in my case because all mysql_ procedural calls are wrapped in a class MySqlDB().
As are mssql_ procedural calls and both inherit from an abstract class that handles common functionallity baseDB().

So to switch I need to edit a few lines in the MySqlDB class.
At least I think it is that simple.
But as I already have a class inheriting from a base class what is the best way to implement the mysqli extension?

By inheriting mysqli from MySqlDB class?
Instantiating mysqli from MySqlDB class?
Or competely abandon MySqlDB and re-write hundreds of scripts?

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#2: Jun 17 '09

re: Porting to mysqli from mysql


Hi.

I would just replace the calls to the mysql extensions with calls to the mysqli extension. In your case it should be as simple as modifying a few lines in your MySqlDB class, right?

This is the point of encapsulation and abstraction in OOP; to be able to modify the inner workings of a class without affecting the code already using it.

Unless you want to have both versions: MySQLDB and MySQLiDB, or something.
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#3: Jun 17 '09

re: Porting to mysqli from mysql


I have only glanced at mysqli tutorials, but don't you have to create a mysqli object to use the extension?
I have also noticed complaints of a performance loss from switching.
Can't corroborate this but idly googling for performance pulls a few articles
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#4: Jun 17 '09

re: Porting to mysqli from mysql


You can use mysqli in two ways, using the mysqli object itself, or the mysql-like functions. The functions were created to ease the transition from the old mysql extension, I believe.

Simply adding a "i" to your old mysql function call should work for most of them.
Just check out the manual entries. They always list a procedural function and a OOP method for each of them.

As to the performance loss, I don't know. I've never tested it myself, but the few articles I've seen about this didn't really worry me.
Anyways, the real power of the Improved MySQL extension is in the prepared statements.
Reply


Similar PHP bytes