我熟悉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);