我熟悉 PHP 和 MYSQLi 连接,并阅读了 PHP 文档,包括http://www.php.net/manual/en/mysqli.persistconns.php,但我想知道建立和关闭的正确方法(性能方面) MYSQLi 中使用 PHP 的连接。
启动和关闭 mysqli 连接的最有效方法是什么?
如果 mysqli 连接在查询期间丢失,正确的处理方法是什么?
这是我当前的设置:
1. Opening a connection at the beginning of the php page
2. Making all the necessary queries through other classes
3. Closing the connection at the end of page
/*
public exampleQuery ($conn, $p1, $p2) {
$stmt = $conn->prepare("SELECT id FROM tbl_name WHERE c1=? AND c2=?");
$stmt->bind_param("ss", $p1, $p2);
$stmt->execute();
// etc..
}
*/
$mysqli_connection = $connectionClass->connectToMYSQLi();
//Execute queries using prepared statements
$queryClass->exampleQuery($mysqli_connection,$param1, $param2);
$queryClass->exampleQueryTwo($mysqli_connection,$param1, $param2);
//etc...
$connectionClass_>closeMYSQLiConnection($mysqli_connection);