是否有一种方法可以获取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();
对于我当前使用MyISAM表引擎进行的全文搜索。任何帮助都将是不可思议的。谢谢。
$starttime = microtime(true);
//Do your query and stuff here
$endtime = microtime(true);
$duration = $endtime - $starttime; //calculates total time taken
NOTE,这将为您提供运行时间,以[[seconds(不是微秒)为单位,直到get_as_float
参数为true。参见this
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) |
+----------+----------+--------------------------+
问候
http://dev.mysql.com/doc/refman/5.0/en/show-profile.html
并在php中显示时间...或解释花费较长时间或详细说明每个查询的SQL语句...由CPU等