title: Difference between $db->query($query) and $result->num_rows
body: <p>I am new to object oriented php. I understand what this line means</p>
  
  <pre><code>$result = $db-&gt;query($query);
  </code></pre>
  
  <p>here $db is the object referring to an instance of class mysqli. Right?</p>
  
  <p>But I do not understand</p>
  
  <pre><code>$total_num_rows = $result-&gt;num_rows;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>while($row = $result-&gt;fetch_array())
  </code></pre>
  
  <p>I know what they do. But can't wrap my head around why its written with $result->...</p>
  
  <p>The entire script : </p>
  
  <pre><code>&lt;?php
  
  $host = "localhost";
  $username = "root";
  $password = "";
  $dbname = "compdb";
  
  @ $db = new mysqli($host, $username, $password, $dbname);
  
  if(mysqli_connect_errno())
  {
      die("Connection could not be established");
  }
  
  $query = "SELECT company_id FROM company_basic_details WHERE company_name = 'ABC'";
  $result = $db-&gt;query($query);
  
  $total_num_rows = $result-&gt;num_rows;
  
  echo "The Results Are : &lt;br&gt;";
  
  while($row = $result-&gt;fetch_array())
  {
      echo $row['company_id'];
  }
  </code></pre>
  
  <p>?></p>