开发者

Zend_DB - Use native MySQL adapter instead of MySQLi or PDO?

The server I'm porting to doesn't have PDO nor Mysqli extensions enabled ( though it is r开发者_如何学Gounning 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.


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.


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


This one works fine: https://github.com/beberlei/Zend_Db-Adapter-for-ext-mysql

I agree with the other answers that you should enable mysqli or pdo_mysql if you can. Since we don't live in a perfect bloody world where developers always have control of their deployment environments, though, I thought I'd actually give you what you asked for too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜