简体   繁体   中英

How to PASS your own mysql connection to Zend_DB?

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);

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM