title: MySQLI Prepared Statement: num_rows & fetch_assoc
body: <p>Below is some poorly written and heavily misunderstood PHP code with no error checking. To be honest, I'm struggling a little getting my head around the maze of PHP->MySQLi functions! Could someone please provide an example of how one would use prepared statements to collect results in an associative array whilst also getting a row count from $stmt? The code below is what I'm playing around with. I think the bit that's throwing me off is using <code>$stmt</code> values after <code>store_result</code> and then trying to collect an assoc array, and I'm not too sure why...</p>
  
  <pre><code>$mysqli = mysqli_connect($config['host'], $config['user'], $config['pass'], $config['db']);
  $stmt = $mysqli-&gt;prepare("SELECT * FROM licences WHERE generated = ?");
  $stmt-&gt;bind_param('i', $core['id']);
  $result = $stmt-&gt;execute();
  $stmt-&gt;store_result();
  
  if ($stmt-&gt;num_rows &gt;= "1") {
  
      while($data = $result-&gt;fetch_assoc()){ 
          //Loop through results here $data[] 
      }
  
  }else{
  
      echo "0 records found";
  
  }
  </code></pre>
  
  <p>I feel a little cheeky just asking for code, but its a working demonstration of my circumstances that I feel I need to finally understand what's actually going on. Thanks a million!</p>