Proper way of connection to MYSQLi using PHP and prepared stmts
===

MYSQLi, PHP, MYSQLi Prepared stmts

I am wondering about the proper way to establish and close connections in MYSQLi using PHP.

*How does PHP handle the connections once the page is reloaded or accessed by a new user simultaneously?*

What is the most efficient way of doing this?

Here is my current setup:

      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);
    $connectionClass_>closeMYSQLiConnection($mysqli_connection);

Also, would creating the prepared stmt in the class be more effiecent than in the function?
For example :

    $prepared_stmt1 = $conn->prepare("SELECT id FROM tbl_name WHERE c1=? AND c2=?");
    
    /*
    public exampleQuery ($conn, $p1, $p2) {
      $prepared_stmt1->bind_param("ss", $p1, $p2);
      $prepared_stmt1->execute();
      // etc..
    }
    */

Please help me understand the most performance efficient way to connect with MYSQLi, MYSQLi prepared stmts, & PHP...