make db connection persistent throught zend framework
Posted
by
kamikaze_pilot
on Stack Overflow
See other posts from Stack Overflow
or by kamikaze_pilot
Published on 2011-11-24T01:42:52Z
Indexed on
2011/11/24
1:50 UTC
Read the original article
Hit count: 219
I'm using zend framework. currently everytime I need to use the db I go ahead and connect to the DB:
function connect(){
$connParams = array("host" => $host,
"port" => $port,
"username" => $username,
"password" => $password,
"dbname" => $dbname);
$db = new Zend_Db_Adapter_Pdo_Mysql($connParams);
return $db
}
so I would just call the connect() function everytime I need to use the db
My question is...suppose I want to reuse $db everywhere in my site and only connect once in the very initial stage of the site load and then close the connection right before the site gets sent to the user, what would be the best practice to accomplish this?
Which file in Zend should I save $db in, what method should I use to save it (global variable?), and which file should I do the connection closing in?
© Stack Overflow or respective owner