問題描述
有什么方法可以獲取 MySQL 查詢的時間(特別是使用 PHP)?完成查詢所花費的實際時間,即.
Is there a way that I can get the time of a MySQL query (specifically with PHP)? The actual time it took to complete the query, that is.
諸如:結果 1 - 10 為棕色.(0.11 秒)
Something such as: Results 1 - 10 for brown. (0.11 seconds)
我試圖尋找一個例子,但無濟于事.這是我的代碼示例:
I tried to look for an example, to no avail. Here is an example of my code:
// 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 表引擎的全文搜索.任何幫助都是不可思議的.謝謝.
For my current full text search using a MyISAM table engine. Any help would be incredible. Thank you.
推薦答案
$starttime = microtime(true);
//Do your query and stuff here
$endtime = microtime(true);
$duration = $endtime - $starttime; //calculates total time taken
注意,由于 get_as_float
參數為真,這將為您提供秒(不是微秒)到最接近微秒的運行時間.見這個
NOTE that this will give you the run time in seconds(not microseconds) to the nearest microsecond due to get_as_float
parameter being true. See this
這篇關于使用 PHP 在 MySQL 中查詢時間結果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!