我熟悉PHP和MYSQLi連接,並閱讀了PHP文檔,包括http://www.php.net/manual/en/mysqli.persistconns.php,但我想知道在MYSQLi中建立和關閉連接的正確方法(性能方面) PHP。使用PHP連接MYSQLi的正確方法
什麼是啓動和關閉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);