php中怎么得到sql语句运行的时间啊?请大家帮忙

解决方案 »

  1.   

    据我所知,在 php 中没有现成的函数.我给你提供个现成的类吧,其实就是上面的说的方法,只不过人家是老大,手很金贵!!!!!!<?php
    class timer {
      var $StartTime = 0;
      var $StopTime = 0;
      function get_microtime() {
        list($usec, $sec) = explode(' ', microtime());
        return ((float)$usec + (float)$sec);
      }
      function start() {
        $this->StartTime = $this->get_microtime();
      }
      function stop() {
        $this->StopTime = $this->get_microtime();
      }
      function spent() {
        return round(($this->StopTime - $this->StartTime) * 1000, 1);
      }
    }$timer = new timer;
    $timer->start();
    // 查询...
    $timer->stop();
    echo $timer->spent();
    ?>
      

  2.   

    如果你是要调试sql语句,不需要在php中引用这个速度值
    那么运行mysql时加 log 或 slow query log ,
    可以在log中查到运行时间,
    相信不会有比这个更准确的了