title: result of prepared select statement as array
body: <p>I would like to get the complete result of a prepared statement as an array (key/value pairs) in order to later use it in a <code>str_replace()</code> function.</p>
  
  <p>My table has three columns, an index and the fields "x1" and "x2". I used the following successfully:</p>
  
  <pre><code>$db = new mysqli("servername", "username", "pw", "dbname");
  
  if($ps1 = $db-&gt;prepare("SELECT x1, x2 FROM my_table")) {
    $ps1-&gt;execute();
    $ps1-&gt;bind_result($search, $replace);
      $result = array();
      while ($ps1-&gt;fetch()) {
        $result[$search] = $replace;
      }
      $ps1-&gt;close();
  }
  </code></pre>
  
  <p>However, I am thinking that there must be a simpler way, without a <code>while</code> loop, getting the complete result, not added up from single rows one by one. </p>
  
  <p>I looked at other questions, and I came up with the following, but it doesn't work ("Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result"):</p>
  
  <pre><code>if($ps1 = $db-&gt;prepare("SELECT x1, x2 FROM my_table")) {
    $ps1-&gt;execute();
    $result = mysqli_fetch_assoc($ps1);
    return $result;
    $ps1-&gt;close();
  }
  </code></pre>
  
  <p>I also tried <code>$result = mysqli_fetch_all($ps1);</code> with no success ( getting "Call to undefined function mysqli_fetch_all()"). </p>
  
  <p>BTW, I am using PHP 5.6.</p>
  
  <hr>
  
  <p>ADDITION after some answers and discussion in comments concerning MYSQLND:</p>
  
  <p><code>phpinfo()</code> displays the following information in its <code>mysqlnd</code> section:</p>
  
  <blockquote>
    <p>Loaded plugins:
    mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password</p>
  </blockquote>