views:

110

answers:

2

All,

I have a PHP application written in Zend Framework with MVC style. I plan to use Zend_DB to connect to the MySQL database and process queries. I am looking for a wrapper class which makes it easy to use Zend_DB class. This wrapper class will have a constructor that connects to the Mysql db using Zend_DB. It will also have a method to return a singleton instance for each and every db connection made.

Something like:

$pptDB = PPTDB::getInstance();
$pptDB->setFetchMode(PPTDB::FETCH_OBJ);
$result = $pptDB->fetchRow('SELECT * FROM bugs WHERE bug_id = 2');
echo $result->bug_description;

Where class PPTDB extends Zend_DB

Is this something feasible to have? If not, how ls would you use Zend_DB in a major application?

Thanks,

A: 

AFAIK it is possible to use Zend_DB as a standalone (well, all classes in that package should also be available of course), but if you're not using the models there is little to gain from is. If you're only interested in the database abstraction I'd recommend PDO, if you want a Zend_DB wrapper Reflection can give you a nice list of properties / functions you can choose to override or not.

http://nl2.php.net/reflection

Wrikken
I am using models in the Zend mvc.. Infact, my db connectivity and all sql queries will be procssed through models.
Vincent
Ah, my apologies, in that case, go ahead, it is pretty easy to define you own desired functions while extending Zend_DB. The only problem I see is when you want to go deeper, as most classes are hardcoded. (Change some inner workings of other classes in the package, I tried very hard once the let Zend_DB return native pdo->fetchobjects into a class instead of toying around, which could simply not be done with only extending, but serious hardcoded alterations in the whole package were required. Succeeded but now worth the trouble :P)
Wrikken
A: 

You should create adapter using Zend_Db::factory() and than use it in Zend_Db_Table_Abstract::setDefaultAdapter(). Then you can get your adapter wherever you want using Zend_Db_Table::getDefaultAdapter() or $table->getAdapter() :)

Tomáš Fejfar