views:

118

answers:

1

I have my own mysql_connect ...etc until i wanted to use ZEND framework in particular with Zend_DB .How do I pass my connection to be used as an adapter to ZEND?

$myconn = mysql_connect('...blab',blah etc...)
eg. Zend_DB_table::setAdapter($myconn);
+1  A: 

Don't connect to DB on your own, rather use the factory

$db = Zend_Db::factory('Pdo_Mysql', array(
    'host'     => '127.0.0.1',
    'username' => 'webuser',
    'password' => 'xxxxxxxx',
    'dbname'   => 'test'
));

This way you can connect to DB, but it will connect only once you need the connection and thus optimize for performance...

michal kralik
I know what you mean but.. you see i already have a connection but anyways is there a way to get the Connection object from Zend_DB? the pure connection used for mysql? like eg. $db= Zend_DB::getConnection() then use $db like on my own object $myobject->setDB($db);
Chopnut
Yes, you can use $db->getConnection() to get the underlying connection database connection object or resource.
michal kralik
I think he's trying to do it the other way around - pass an existing resource into a Db instance.
David Caunt