title: How do I display execution time of a MySQL query in PHP?
body: <p>I am working on a PHP application that takes queries in a text box and returns paginated results.  As part of the application I want to report the running time of the query.</p>
  
  <p>Here is what I have done so far.</p>
  
  <p>I started off by enabling profiling in by directly entering in the text box and running the script:</p>
  
  <pre class="lang-sql prettyprint-override"><code>set global profiling = 1
  </code></pre>
  
  <p>Using the provided text box I enter the following query:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select @@profiling
  </code></pre>
  
  <p>And get:</p>
  
  <pre class="lang-sql prettyprint-override"><code>1
  </code></pre>
  
  <p>Finally, I run the query as so:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select * from log
  </code></pre>
  
  <p>However, when I run the command for to profile the query:</p>
  
  <pre class="lang-sql prettyprint-override"><code>show profiles
  </code></pre>
  
  <p>I receive no result and no content displayed on the page.</p>
  
  <p>Since I see no table after the command "show profiles" does this mean that there are not sufficient privileges or am I missing another step?</p>
  
  <p>I followed the procedure on:</p>
  
  <p><a href="https://stackoverflow.com/questions/11274892/measuring-actual-mysql-query-time">Measuring actual MySQL query time</a></p>
  
  <p>Please advise.</p>
  
  <p>My PHP code is as follows:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
      if($_POST)
      {
          $db = new PDO('mysql:host=localhost;dbname=&lt;dbname&gt;;charset=utf8', 'user', 'pass');
          $stmt = $db-&gt;prepare($_POST['query']);
          $stmt-&gt;execute();
  
          $records = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
  
          $errmsg = $stmt-&gt;errorInfo()[2]; //Output the error message - Index 2 of the array
  
          echo $errmsg;
      }  
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt;
  &lt;head&gt;
  &lt;title&gt;Log&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="post" id="queryform"&gt;
          &lt;div class="label"&gt;
              &lt;span class="label"&gt;Enter SQL Query&lt;/span&gt;
          &lt;/div&gt;
          &lt;div class="input"&gt;
              &lt;input type="text" name="query" size="150" value="&lt;?=$_POST['query']?&gt;" /&gt;
          &lt;/div&gt;
      &lt;/form&gt;
      &lt;? if (isset($records)): ?&gt;
      &lt;table border="1"&gt;
          &lt;? foreach($records as $record): ?&gt;
              &lt;tr&gt;
                  &lt;? foreach($record as $colname =&gt; $value): ?&gt;
                      &lt;td&gt;
                         &lt;?=$value;?&gt;
                      &lt;/td&gt;
                  &lt;? endforeach; ?&gt;    
              &lt;/tr&gt;
          &lt;? endforeach; ?&gt;
      &lt;/table&gt;
  
      &lt;? endif; ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any help would be appreciated.</p>