无预连接
function db_con_basic(){
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = 'test';
$pwd = 'test';
try {
$dbh = new PDO($dsn, $user, $pwd);
$dbh -> query('use test;');
} catch (Exception $e) {
print "Error!: " . $e->getMessage() ;
die();
}
return $dbh;
}
while(1){
$pdo=db_con_basic();
$cxArr=$pdo->query("select * from test")->fetchAll(PDO::FETCH_ASSOC);
$pdo=null;
}
?>
大量time_wait
有预连接,无time_wait
function db_con_basic(){
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = 'test';
$pwd = 'test';
try {
$dbh = new PDO($dsn, $user, $pwd);
$dbh -> query('use test;');
} catch (Exception $e) {
print "Error!: " . $e->getMessage() ;
die();
}
return $dbh;
}
$pdo=db_con_basic();
while(1){
$cxArr=$pdo->query("select * from test")->fetchAll(PDO::FETCH_ASSOC);
}
$pdo=null;
?>
阅读(1905) | 评论(0) | 转发(0) |