使用Zend_Db :: factory和PDO_MYSQL时,使用PHP代码设置连接超时的正确(或更好)方法是什么。
我有:
$params = array (
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'dbname' => 'mydb',
'charset' => 'UTF8',
);
$db = Zend_Db::factory('PDO_MYSQL', $params);
a。)
$db->getConnection()->setAttribute(PDO::ATTR_TIMEOUT, 600);
湾)
$sql = "SET SESSION wait_timeout = 600";
$db->getConnection()->query($sql);
答案 0 :(得分:1)
将连接超时减少到3秒:
$params = array (
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'dbname' => 'mydb',
'charset' => 'UTF8',
'driver_options' => [
\PDO::ATTR_TIMEOUT => 3
]
);
$db = Zend_Db::factory('PDO_MYSQL', $params);