title: How to execute a query multiple time in mysqli Connection using PHP
body: <p>only work when $i=0; </p>
  
  <pre><code>&lt;?php   
          include 'db.php';
          $con = new db();
          $db = $con-&gt;getConnection();
              $i = 0;
          while($i &lt;= 10){
              $query = "call rep_summary('$date')";
              $result = $db-&gt;query($query);
              while ($data = $result-&gt;fetch_assoc()) {
                  $user = $data['username'];
                  $id = $data['id'];
                  echo $user;
                  }
  
              $i++;
          }
          $db-&gt;close();
  
      ?&gt;
  </code></pre>
  
  <p>the following code work fine but its take too much time and for that I want to reuse connection</p>
  
  <pre><code>&lt;?php   
     include 'db.php';
  
     $i = 0;
      while($i &lt;= 10){
          $con = new db();
          $db = $con-&gt;getConnection();
          $query = "call rep_summary('$date')";
          $result = $db-&gt;query($query);
          while ($data = $result-&gt;fetch_assoc()) {
              $user = $data['username'];
              $id = $data['id'];
              echo $user;
              }
  
          $i++;
  
      }
  $db-&gt;close();
  
  ?&gt;
  </code></pre>
  
  <p>and db class</p>
  
  <pre><code>&lt;?php
  
  class db {
  
      var $_host = "localhost";
      var $_user = "root";
      var $_password = "";
      var $_database = "test";
      var $db;
  
      public function __construct() {
          $this-&gt;db = new mysqli($this-&gt;_host, $this-&gt;_user, $this-&gt;_password, $this-&gt;_database);
          $this-&gt;db-&gt;set_charset("utf8");
      }
  
      public function getConnection() {
          if ($this-&gt;db-&gt;connect_errno &gt; 0) {
              die('Unable to connect to database [' . $this-&gt;db-&gt;connect_error . ']');
          }
          return $this-&gt;db;
      }
  
  }
  </code></pre>
  
  <p>How I can execute query in a single connection</p>