title: How to close the MySQLi connection?
body: <p>have the following code, if I try to execute it in the controller, create an instance of this class and consistently cause get_one, and then get_two, it returns an error because get_two mysql-connection is already closed.</p>
  
  <pre><code>class Foo extends Bar
  {
      function __construct()
      {
  
          parent::__construct();
  
          $this-&gt;mysqli = new mysqli($this-&gt;cfg-&gt;db-&gt;host, 
                                     $this-&gt;cfg-&gt;db-&gt;user, 
                                     $this-&gt;cfg-&gt;db-&gt;password, 
                                     $this-&gt;cfg-&gt;db-&gt;database);
          $this-&gt;mysqli-&gt;query('SET NAMES utf8');
  
      }
  
      public function get_one()
      {
  
          $table_one = array();
  
          $result = $this-&gt;mysqli-&gt;query('SELECT * FROM `table_one`');
  
          for ($i=0; $row = $result-&gt;fetch_assoc(); $i++) { 
              $table_one[] = $row;
          }
  
          $result-&gt;close();
          $this-&gt;mysqli-&gt;close();
  
          return $table_one;
  
      }
  
  
      public function get_two()
      {
  
          $table_two = array();
  
          $result = $this-&gt;mysqli-&gt;query('SELECT * FROM `table_two`');
  
          for ($i=0; $row = $result-&gt;fetch_assoc(); $i++) { 
              $table_two[] = $row;
          }
  
          $result-&gt;close();
          $this-&gt;mysqli-&gt;close();
  
          return $table_two;
  
      }
  
  }
  </code></pre>
  
  <p>Comes to mind only this</p>
  
  <pre><code>public function get_one($keep = false)
  {
      ...
      if(!$keep)
        $this-&gt;mysqli-&gt;close();
      ...
  }
  </code></pre>
  
  <p>How to right way?</p>