Query time result in MySQL w/ PHP(使用 PHP 在 MySQL 中查询时间结果)
问题描述
有什么方法可以获取 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 中查询时间结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 PHP 在 MySQL 中查询时间结果
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
