title: MySQL PHP - Fatal error, query fails on page but not PHPMyAdmin
body: <p>I have a query containing a MySQL variable to produce a running total of a time value, and it works and produces results/rows in PHPMyAdmin, but as soon as I try it on my site it produces <code>"Fatal error: Call to a member function fetch_assoc() on a non-object"</code>. If anyone could help me identify the issue here it would be greatly appreciated.</p>
  
  <p><strong>Query used in PHPMyAdmin [works]:</strong></p>
  
  <pre><code>SET @total_duration := 0;
  SELECT sec_to_time(@total_duration := @total_duration + time_to_sec(duration)) AS cumulative_duration
  FROM tbl_flights
  ORDER BY tbl_flights.flight_id ASC
  </code></pre>
  
  <p><strong>Query within PHP file [does not work]:</strong></p>
  
  <pre><code>&lt;?php
  
  include('config.php');
  
  $sql = "SET @total_duration := 0;
          SELECT sec_to_time(@total_duration := @total_duration + time_to_sec(duration)) AS cumulative_duration
          FROM tbl_flights
          ORDER BY tbl_flights.flight_id ASC";
  
  $result = $conn-&gt;query($sql);
  
  while ($row = $result-&gt;fetch_assoc()) {
  
      echo $row['cumulative_duration'];
  
  }
  
  ?&gt;
  </code></pre>