私はPHPとMYSQLiの接続に精通しており、http: //www.php.net/manual/en/mysqli.persistconns.phpを含む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);