1--TEST-- 2Bug #79375: mysqli_store_result does not report error from lock wait timeout 3--SKIPIF-- 4<?php 5if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded'); 6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc'); 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9?> 10--FILE-- 11<?php 12require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 13 14function createDB(): PDO { 15 $db = MySQLPDOTest::factory(); 16 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 17 $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 18 return $db; 19} 20 21$db = createDB(); 22$db2 = createDB(); 23$db->query('DROP TABLE IF EXISTS test'); 24$db->query('CREATE TABLE test (first int) ENGINE = InnoDB'); 25$db->query('INSERT INTO test VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9)'); 26 27function testNormalQuery(PDO $db, string $name) { 28 $db->exec("SET innodb_lock_wait_timeout = 1"); 29 $db->exec("START TRANSACTION"); 30 $query = "SELECT first FROM test WHERE first = 1 FOR UPDATE"; 31 echo "Running query on $name\n"; 32 try { 33 $stmt = $db->query($query); 34 echo "Got {$stmt->rowCount()} for $name\n"; 35 } catch (PDOException $e) { 36 echo $e->getMessage()."\n"; 37 } 38} 39 40function testPrepareExecute(PDO $db, string $name) { 41 $db->exec("SET innodb_lock_wait_timeout = 1"); 42 $db->exec("START TRANSACTION"); 43 $query = "SELECT first FROM test WHERE first = 1 FOR UPDATE"; 44 echo "Running query on $name\n"; 45 $stmt = $db->prepare($query); 46 try { 47 $stmt->execute(); 48 echo "Got {$stmt->rowCount()} for $name\n"; 49 } catch (PDOException $e) { 50 echo $e->getMessage()."\n"; 51 } 52} 53 54function testUnbuffered(PDO $db, string $name) { 55 $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); 56 $db->exec("SET innodb_lock_wait_timeout = 1"); 57 $db->exec("START TRANSACTION"); 58 $query = "SELECT first FROM test WHERE first = 1 FOR UPDATE"; 59 echo "Running query on $name\n"; 60 $stmt = $db->prepare($query); 61 $stmt->execute(); 62 try { 63 $rows = $stmt->fetchAll(); 64 $count = count($rows); 65 echo "Got $count for $name\n"; 66 } catch (PDOException $e) { 67 echo $e->getMessage()."\n"; 68 } 69} 70 71testNormalQuery($db, 'first connection'); 72testNormalQuery($db2, 'second connection'); 73unset($db); 74unset($db2); 75echo "\n"; 76 77$db = createDB(); 78$db2 = createDB(); 79testPrepareExecute($db, 'first connection'); 80testPrepareExecute($db2, 'second connection'); 81unset($db); 82unset($db2); 83echo "\n"; 84 85$db = createDB(); 86$db2 = createDB(); 87testUnbuffered($db, 'first connection'); 88testUnbuffered($db2, 'second connection'); 89unset($db); 90unset($db2); 91echo "\n"; 92 93?> 94--CLEAN-- 95<?php 96require __DIR__ . '/mysql_pdo_test.inc'; 97MySQLPDOTest::dropTestTable(); 98?> 99--EXPECT-- 100Running query on first connection 101Got 1 for first connection 102Running query on second connection 103SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction 104 105Running query on first connection 106Got 1 for first connection 107Running query on second connection 108SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction 109 110Running query on first connection 111Got 1 for first connection 112Running query on second connection 113SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction 114