1--TEST-- 2Bug #42499 (Multi-statement execution via PDO::exec() makes connection unusable) 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 8MySQLPDOTest::skip(); 9?> 10--FILE-- 11<?php 12require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 13$db = MySQLPDOTest::factory(); 14 15function bug_42499($db) { 16 $db->exec("DROP TABLE IF EXISTS test_42499"); 17 $db->exec("CREATE TABLE test_42499(id CHAR(1)); INSERT INTO test_42499(id) VALUES ('a')"); 18 19 $stmt = $db->query('SELECT id AS _id FROM test_42499'); 20 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 21 22 // You must not use exec() to run statements that create a result set! 23 $db->exec('SELECT id FROM test_42499'); 24 // This will bail at you because you have not fetched the SELECT results: this is not a bug! 25 $db->exec("INSERT INTO test_42499(id) VALUES ('b')"); 26} 27 28print "Emulated Prepared Statements...\n"; 29$db = MySQLPDOTest::factory(); 30$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); 31$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1); 32bug_42499($db); 33 34print "Native Prepared Statements...\n"; 35$db = MySQLPDOTest::factory(); 36$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); 37$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1); 38bug_42499($db); 39 40print "done!"; 41?> 42--CLEAN-- 43<?php 44require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 45$db = MySQLPDOTest::factory(); 46$db->exec("DROP TABLE IF EXISTS test_42499"); 47?> 48--EXPECTF-- 49Emulated Prepared Statements... 50array(1) { 51 [0]=> 52 array(1) { 53 ["_id"]=> 54 string(1) "a" 55 } 56} 57 58Warning: PDO::exec(): SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in %s on line %d 59Native Prepared Statements... 60array(1) { 61 [0]=> 62 array(1) { 63 ["_id"]=> 64 string(1) "a" 65 } 66} 67 68Warning: PDO::exec(): SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in %s on line %d 69done! 70