title: mysqli_num_rows is 1 but mysql_fetch_assoc returns null
body: <p>I am having a bit of an issue with a mysqli connection, seem to be falling at the first hurdle. Before going ahead, I have tested the connection and it working, the query is correct but a var_dump of the values in mysql_fetch_assoc and mysql_fetch_array are null.</p>
  
  <p>The code checks to see if a row with the value exists, if it does it stops andif it doesn't then it pulls a value from the DB. This seems to be working fine up to the part of pulling the value. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>    db = new database('localhost', 'username', 'password', 'my_db');
  
      $db-&gt;query("SELECT * FROM `codes` WHERE `code` = '$ccode'");
  
      if ($db-&gt;numRows() == 0) 
      {
          echo "No value was found";
  
      }
      else
      {
          foreach($db-&gt;rows() as $email)
          {
              echo $email['um-email'];
              echo $ccode;
          }
  
      }
  
  
      $db-&gt;disconnect();   
  }
  </code></pre>
  
  <p>Here is the code for the connection class page:</p>
  
  <pre><code>class database
  {
  protected $_link, $_result, $_numRows, $_content; 
  public function __construct($server, $username, $password, $db)
  {
      $this-&gt;_link = mysqli_connect($server, $username, $password, $db);
      mysqli_select_db($this-&gt;_link, $db);
  }
  
  public function disconnect()
  {
      mysqli_close($this-&gt;_link);
  }
  
  public function query($sql)
  {
      $this-&gt;_result = mysqli_query($this-&gt;_link, $sql);
  
      echo $sql;
  
      $this-&gt;_numRows = mysqli_num_rows($this-&gt;_result);
  }
  
  public function content()
  {
      return $this-&gt;_content;    
  }
  
  
  
  
  public function display_content()
  {
      $arows = array();
      for($x = 0; $x &lt; $this-&gt;numRows(); $x++)
      {
          $arows[] = mysqli_fetch_array($this-&gt;_result);
      }
      echo var_dump($arows);
      return $arows;
  }
  
  public function numRows()
  {
      return $this-&gt;_numRows;
  }
  
  public function rows()
  {
      $rows = array();
      for($x = 0; $x &lt; $this-&gt;numRows(); $x++)
      {
          $rows[] = mysqli_fetch_assoc($this-&gt;_result);
      }
      echo var_dump($rows);
      return $rows;
  }
  }
  </code></pre>
  
  <p>At a real loss as to what is causing the issue, the fact that the DB has got value in there and is returning the number of rows, I don't understand why the arrays are null.</p>
  
  <p>If the code examples above, I am trying to get the email address from the first code segment with this: </p>
  
  <pre><code>foreach($db-&gt;display_content() as $aemail)
      {
          echo $aemail['um-email'];
      }
  </code></pre>
  
  <p>Ultimately that will be assigned to a session variable for later for the time being I am using echo to see if it has a value. For the moment there are bits that could be protected from SQL injection but I would like to get this working before adding validation.</p>
  
  <p>The exact message returned from the var_dump is:</p>
  
  <pre><code>array (size=1)
  0 =&gt; 
  array (size=3)
    'ID' =&gt; string '3' (length=1)
    'code' =&gt; string '12345' (length=5)
    'um_email' =&gt; string 'billybob@bobmail.com' (length=20)
  </code></pre>
  
  <p>For the TL;DR number of rows is 1 when there is a correct value, mysqli_fetch_array/assoc return null.</p>
  
  <p>Many thanks I appreciate all of the help</p>
  
  <p>UPDATE: Removed the line as suggested by Mark Baker and now it seems the data is now being store in the array (looking at the var_dump) however I am now receiving an " Undefined offset: 0" value.</p>