|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76048 PDO Mysql max_execution_time is not respected
Submitted: 2018-03-05 07:37 UTC Modified: 2020-12-10 11:01 UTC
Avg. Score:4.7 ± 0.7
Reproduced:17 of 17 (100.0%)
Same Version:7 (41.2%)
Same OS:8 (47.1%)
From: rishabh dot pugalia at gmail dot com Assigned: nikic (profile)
Status: Closed Package: PDO MySQL
PHP Version: 7.0.28 OS: Mac
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
20 - 19 = ?
Subscribe to this entry?

 [2018-03-05 07:37 UTC] rishabh dot pugalia at gmail dot com
PDO does not respect MySQL 5.7's new feature - max_execution_time()

The code below will explain further. Sadly the mysqli_* seg faults if the same native prepared statement is executed.

Test script:

$connection = new PDO("mysql:host=;dbname=experiments", 'root', '');

// Setting this to true triggers a query directly but still the result is same (which is also weird)
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

// The query is supposed to take about 6s to execute
$stmt = $connection->prepare("select /*+ max_execution_time(1000) */ * from users where name = ?");




Expected result:
It should throw an error around what Mysql natively does:

"ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded"

Actual result:
array(0) {
array(3) {
  string(5) "00000"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-05 08:18 UTC] saurav1991 at gmail dot com
When client side prepared statement is used i.e PDO::ATTR_EMULATE_PREPARES => true, the expected error PDOException: SQLSTATE[HY000]: General error: 3024 Query execution was interrupted, maximum statement execution time exceeded is thrown

However on using server side prepared statements, this exception is not thrown.

Compared with a ruby script using the mysql2 client. The exception is thrown both when server side prepared statement is used and when prepared query is sent to mysql directly.

This might have to do with how the prepared statement APIs of libmysqlclient are being used internally.
 [2018-03-05 08:32 UTC] rishabh dot pugalia at gmail dot com
-Summary: max_execution_time is not respected +Summary: PDO Mysql max_execution_time is not respected
 [2018-03-05 08:32 UTC] rishabh dot pugalia at gmail dot com
Adding "PDO Mysql" to the title.
 [2018-06-20 15:56 UTC] anthony at catsone dot com
I'm also running into this issue. 100% reproducible as per the original reporter.
 [2019-07-01 06:50 UTC] Fractalizer at yandex dot ru
Is reproducable on PHP 7.2 also. Any chances to have this fixed?
 [2020-02-25 12:00 UTC] thijs at keeping dot nl
Reproduced using PHP 7.4 on both Ubuntu 18.04.4 and macOS 10.15.3.
 [2020-12-10 11:01 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-12-10 11:01 UTC]
Can't reproduce this on current 7.4/8.0 any more, can reproduce on 7.3. I believe the fix for InnoDB lock errors also covered this case. (Please tell me if you still see this issue on current 7.4/8.0.)
 [2021-09-03 12:23 UTC] thanhtung4948 at gmail dot com
I still face this problem using PHP 7.4
Can you confirm?
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 17:03:35 2021 UTC