查询时间结果在MySQL w/PHP中

bob*_*obb 13 php mysql time myisam

有没有办法让我可以获得MySQL查询的时间(特别是使用PHP)?完成查询所花费的实际时间,即.

例如:结果1 - 10为棕色.(0.11秒)

我试图寻找一个例子,但无济于事.这是我的代码示例:

                    // prepare sql statement
                $stmt = $dbh->prepare("SELECT ijl, description, source, user_id, timestamp FROM Submissions WHERE MATCH (ijl, description) AGAINST (?)");

                // bind parameters
                $stmt->bindParam(1, $search, PDO::PARAM_STR);

                // execute prepared statement
                $stmt->execute();
Run Code Online (Sandbox Code Playgroud)

对于我目前使用MyISAM表引擎的全文搜索.任何帮助都会令人难以置信.谢谢.

小智 41

$starttime = microtime(true);

//Do your query and stuff here

$endtime = microtime(true);
$duration = $endtime - $starttime; //calculates total time taken
Run Code Online (Sandbox Code Playgroud)

这将为您提供以微秒为单位的运行时间.


Pat*_*fre 5

这可能会对你有所帮助

http://dev.mysql.com/doc/refman/5.0/en/show-profile.html

mysql> SET profiling = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CREATE TABLE T1 (id INT);
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW PROFILES;
+----------+----------+--------------------------+
| Query_ID | Duration | Query                    |
+----------+----------+--------------------------+
|        0 | 0.000088 | SET PROFILING = 1        |
|        1 | 0.000136 | DROP TABLE IF EXISTS t1  |
|        2 | 0.011947 | CREATE TABLE t1 (id INT) |
+----------+----------+--------------------------+
Run Code Online (Sandbox Code Playgroud)

问候