|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-03-05 07:37 UTC] rishabh dot pugalia at gmail dot com
Description:
------------
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:
---------------
<?php
$connection = new PDO("mysql:host=127.0.0.1;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 = ?");
$stmt->execute(['b08588d6-0f12-11e8-9637-7e0088aab9a1']);
var_dump($stmt->fetchAll());
var_dump($connection->errorInfo());
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) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 17:00:01 2025 UTC |
I can reproduce with 8.2 and MySQL 8.0: ########## PHP 8.2.12 (cli) (built: Oct 28 2023 01:45:57) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.12, Copyright (c) Zend Technologies with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans ########## test script: ------------------------ <?php try { $dbh = new PDO( 'mysql:host=db;dbname=dbname', 'root', 'root', [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ] ); $dbh->exec('SET SESSION MAX_EXECUTION_TIME=1000'); var_dump((new DateTime())->format('Y-m-d H:i:s.u')); $stmt = $dbh->query('SELECT SLEEP(10), version()'); var_dump((new DateTime())->format('Y-m-d H:i:s.u')); var_dump($stmt->fetchAll()); var_dump($stmt->errorInfo()); var_dump($dbh->errorInfo()); } catch (\Throwable $e) { exit(var_dump($e->getMessage())); } ------------------------ output is ------------------------ string(26) "2023-11-11 11:47:22.527547" string(26) "2023-11-11 11:47:23.528134" array(1) { [0]=> array(2) { ["SLEEP(10)"]=> int(1) ["version()"]=> string(6) "8.0.28" } } array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL } array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL } ------------------------