title: mySQLi prepared statement unable to get_result()
body: <p>I am totally confused by mySQLi.  Although I have been using procedural mysql calls for years, I want to get used to making prepared statements for the db security/mySQL injection protection it offers.  I am trying to write a simple select statement (yes I know making a procedural call for this offers performance enhancement).  When run, I get all the echoes until I hit the <code>$result = $stmt-&gt;get_result();</code> component.  It all seems fairly straightforward to me, but I am at a loss after hours of reading manuals on mySQLi.  Any ideas why this would be failing?</p>
  
  <p>*note:  this is a test environment and while no sanitizing/escaping of characters is taking place, I am only passing valid content into the variables $username and $email.  And also, I have looked all over SO to find the solution to my issue.</p>
  
  <pre><code>function checkUsernameEmailAvailability($username, $email) {
      //Instantiate mysqli connection
      @$mysqli = new mysqli(C_HOST,C_USER,C_PASS,C_BASE) or die("Failed to connect to MySQL database...");
      if (!$mysqli)
      {
          echo 'Error: Could not connect to database.  Please try again later...';
          exit;
      } else {
          echo 'mysqli created';
      }
  
      /* Create a prepared statement */   
      if($stmt = $mysqli -&gt; prepare("SELECT username,email FROM tb_users WHERE username=? OR email=?")) {
          echo '&lt;br /&gt;MYSQLi: ';
  
          /* Bind parameters s - string, b - boolean, i - int, etc */
          $stmt -&gt; bind_param("ss", $username, $email);
          echo '&lt;br /&gt;paramsBound...';
  
          /* Execute it */
          $stmt -&gt; execute();     
          echo '&lt;br /&gt;Executed';
  
          $result = $stmt-&gt;get_result();
          echo '&lt;br /&gt;Result acquired';
  
          /* now you can fetch the results into an array - NICE */
          $myrow = $result-&gt;fetch_assoc();
          echo '&lt;br /&gt;Fetched';
  
  
          /* Close statement */
          /$stmt -&gt; close();
          echo '&lt;br /&gt;Done mysqli';
      }
  }    
  </code></pre>
  
  <p>Also, do I have to instantiate a mysqli every time I call a function?  I'm assuming they're not persistent db connects like in procedural mysql.  Yes, I am aware this is a scope issue, and no I have not been able to understand the scoping of this class variable.  When I declared it outside of the function, it was not available when I came into the function.</p>
  
  <p><em>UPDATE</em>
  if I change line 12 from:</p>
  
  <pre><code>if($stmt = $mysqli -&gt; prepare("SELECT username,email FROM tb_users WHERE username=? OR email=?")) {
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>    $stmt = $mysqli-&gt;stmt_init();
      if($stmt = $mysqli -&gt; prepare("SELECT username,email FROM tb_users WHERE username=? OR email=?")) {
          if(!stmt) echo 'Statement prepared'; else echo 'Statement NOT prepared';
  </code></pre>
  
  <p>I get Statement NOT prepared.  Now I'm even more confused....</p>
  
  <p><em><strong>UPDATE:</em></strong>
   I contacted my hosting provider and apparently mySQLi is supported, and the mysqlnd driver is present.  Perhaps there is a way to simply test this?  Although they usually have given me pretty knowledgeable answers in the past.</p>
  
  <p><em><strong>UPDATE...AGAIN:</em></strong> I checked my server capabilities myself and discovered, while mysqli and PDO are present, mysqlnd is not.  Thusly, I understand why get_result() will not work (mysqlnd required I think), I still don't understand why the prepared statement itself will not work.</p>