views:

672

answers:

2

The server I'm porting to doesn't have PDO nor Mysqli extensions enabled ( though it is running PHP5 ). I don't see any MySql.php class in Zend/Db/Adapter - is there some convention to using native MySQL? Or some sort of workaround? Perhaps using an older version of Zend?

And I don't have access to modify the php.ini.

+1  A: 

No, there is no native adapters. But you can try to write your own, it's simple. You even don't need to create all methods which the other adapters have (but you must implement all abstract methods - at least leave them empty, or you will be getting a Fatal Error). You can use a Mysqli adapter (for example) as a base for yours (I think, not a base class, but an example of code).

class My_Db_Adapter_MySQL extends Zend_Db_Adapter_Abstract {
     // your code
}

and then just use My_Db_Adapter_MySQL as a name for your adapter

valya
Seriously? No one has ever wrote a native MySQL adapter for the latest version of Zend?
meder
Maybe someone has, but in official version of ZF there is no such adapters. Of course, instead of writing your own, you can try to google for it
valya
Uh. Mysqli IS a 'native' adapter in the sense that you're using it. The plain vanilla Mysql extension for PHP is slow, buggy, lacking features and depreciated.
jason
If only I were allowed access to the server to actually enable or recompile it so that a `mysqli` or `pdo` is available, that'd be great. Like I stated I don't really have any choice.
meder
+3  A: 

I worked on the Zend_Db adapters quite a bit while I worked on the ZF project.

We couldn't support a Zend_Db adapter for the plain MySQL extension, because so much of Zend_Db relies on prepared statements, as well as other features that are only found in the MySQLi and PDO_MySQL extensions.

There is no advantage to using the MySQL extension. There's nothing "native" about it. It's just an API binding for the MySQL client library.

I'd recommend that you enable one of MySQLi or PDO_MySQL, but you say you have no access to do that. Then your choices are:

  • Move to a different server that does have those PHP extensions enabled, or gives you access to enable them;
  • Use another RDBMS besides MySQL, if Zend_Db supports the PHP extension for that other database and the extension is enabled on your server;
  • Forgo Zend_Db altogether and use the MySQL extension directly.

I recommend the first choice.


User @farzad claims he has implemented a Zend_Db adapter for ext/mysql, but had to sacrifice some of the functionality of Zend_Db.

Bill Karwin
I ended up writing my first db class to use mysql directly, was pretty decent practice. My big mistake was assuming the client's server had `mysqli` or `pdo`, next time I'll ask for sure.
meder