1--TEST-- 2Bug #80458 PDOStatement::fetchAll() throws for upsert queries 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 14$db = MySQLPDOTest::factory(); 15$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 16$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 17$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 18 19$db->query('CREATE TABLE test_80458 (first INT) ENGINE = InnoDB'); 20$res = $db->query('INSERT INTO test_80458(first) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16)'); 21var_dump($res->fetchAll()); 22 23$stmt = $db->prepare('DELETE FROM test_80458 WHERE first=1'); 24$stmt->execute(); 25var_dump($stmt->fetchAll()); 26 27$res = $db->query('DELETE FROM test_80458 WHERE first=2'); 28var_dump($res->fetchAll()); 29 30$stmt2 = $db->prepare('DELETE FROM test_80458 WHERE first=3'); 31$stmt2->execute(); 32foreach($stmt2 as $row){ 33 // expect nothing 34} 35 36$stmt3 = $db->prepare('DELETE FROM test_80458 WHERE first=4'); 37$stmt3->execute(); 38var_dump($stmt3->fetch(PDO::FETCH_ASSOC)); 39 40$stmt = $db->prepare('SELECT first FROM test_80458 WHERE first=5'); 41$stmt->execute(); 42var_dump($stmt->fetchAll()); 43 44$procedure_nores = 'nores_bug80458_pdo_mysql_p'; 45 46$db->exec("CREATE PROCEDURE {$procedure_nores}() BEGIN DELETE FROM test_80458 WHERE first=6; END;"); 47$stmt4 = $db->prepare("CALL {$procedure_nores}()"); 48$stmt4->execute(); 49var_dump($stmt4->fetchAll()); 50$db->exec("DROP PROCEDURE IF EXISTS {$procedure_nores}"); 51 52$procedure_ret = 'ret_bug80458_pdo_mysql_p'; 53 54$db->exec("CREATE PROCEDURE {$procedure_ret}() BEGIN SELECT first FROM test_80458 WHERE first=7; END;"); 55$stmt5 = $db->prepare("CALL {$procedure_ret}()"); 56$stmt5->execute(); 57var_dump($stmt5->fetchAll()); 58$stmt5->nextRowset(); // needed to fetch the empty result set of CALL 59var_dump($stmt5->fetchAll()); 60$db->exec("DROP PROCEDURE IF EXISTS {$procedure_ret}"); 61 62/* With emulated prepares */ 63print("Emulated prepares\n"); 64$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); 65 66$stmt = $db->prepare('DELETE FROM test_80458 WHERE first=8'); 67$stmt->execute(); 68var_dump($stmt->fetchAll()); 69 70$res = $db->query('DELETE FROM test_80458 WHERE first=9'); 71var_dump($res->fetchAll()); 72 73$stmt2 = $db->prepare('DELETE FROM test_80458 WHERE first=10'); 74$stmt2->execute(); 75foreach($stmt2 as $row){ 76 // expect nothing 77} 78 79$stmt3 = $db->prepare('DELETE FROM test_80458 WHERE first=11'); 80$stmt3->execute(); 81var_dump($stmt3->fetch(PDO::FETCH_ASSOC)); 82 83$stmt = $db->prepare('SELECT first FROM test_80458 WHERE first=12'); 84$stmt->execute(); 85var_dump($stmt->fetchAll()); 86 87$db->exec("CREATE PROCEDURE {$procedure_nores}() BEGIN DELETE FROM test_80458 WHERE first=13; END;"); 88$stmt4 = $db->prepare("CALL {$procedure_nores}()"); 89$stmt4->execute(); 90var_dump($stmt4->fetchAll()); 91$db->exec("CREATE PROCEDURE {$procedure_ret}() BEGIN SELECT first FROM test_80458 WHERE first=14; END;"); 92$stmt5 = $db->prepare("CALL {$procedure_ret}()"); 93$stmt5->execute(); 94var_dump($stmt5->fetchAll()); 95$stmt5->nextRowset(); // needed to fetch the empty result set of CALL 96var_dump($stmt5->fetchAll()); 97$db->exec("DROP PROCEDURE IF EXISTS {$procedure_ret}"); 98 99$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 100$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); 101 102$stmt = $db->prepare('DELETE FROM test_80458 WHERE first=15'); 103$stmt->execute(); 104var_dump($stmt->fetchAll()); 105 106$stmt = $db->prepare('SELECT first FROM test_80458 WHERE first=16'); 107$stmt->execute(); 108var_dump($stmt->fetchAll()); 109?> 110--CLEAN-- 111<?php 112require_once __DIR__ . '/inc/mysql_pdo_test.inc'; 113$db = MySQLPDOTest::factory(); 114$db->exec('DROP TABLE IF EXISTS test_80458'); 115$db->exec('DROP PROCEDURE IF EXISTS nores_bug80458_pdo_mysql_p'); 116$db->exec('DROP PROCEDURE IF EXISTS ret_bug80458_pdo_mysql_p'); 117?> 118--EXPECT-- 119array(0) { 120} 121array(0) { 122} 123array(0) { 124} 125bool(false) 126array(1) { 127 [0]=> 128 array(2) { 129 ["first"]=> 130 string(1) "5" 131 [0]=> 132 string(1) "5" 133 } 134} 135array(0) { 136} 137array(1) { 138 [0]=> 139 array(2) { 140 ["first"]=> 141 string(1) "7" 142 [0]=> 143 string(1) "7" 144 } 145} 146array(0) { 147} 148Emulated prepares 149array(0) { 150} 151array(0) { 152} 153bool(false) 154array(1) { 155 [0]=> 156 array(2) { 157 ["first"]=> 158 string(2) "12" 159 [0]=> 160 string(2) "12" 161 } 162} 163array(0) { 164} 165array(1) { 166 [0]=> 167 array(2) { 168 ["first"]=> 169 string(2) "14" 170 [0]=> 171 string(2) "14" 172 } 173} 174array(0) { 175} 176array(0) { 177} 178array(1) { 179 [0]=> 180 array(2) { 181 ["first"]=> 182 string(2) "16" 183 [0]=> 184 string(2) "16" 185 } 186} 187