1--TEST-- 2PDO::MYSQL_ATTR_MULTI_STATEMENTS 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9$db = MySQLPDOTest::factory(); 10?> 11--INI-- 12error_reporting=E_ALL 13--FILE-- 14<?php 15 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 16 17 $dsn = MySQLPDOTest::getDSN(); 18 $user = PDO_MYSQL_TEST_USER; 19 $pass = PDO_MYSQL_TEST_PASS; 20 21 $table = sprintf("test_%s", md5(mt_rand(0, PHP_INT_MAX))); 22 $db = new PDO($dsn, $user, $pass); 23 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); 24 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 25 $db->exec(sprintf('DROP TABLE IF EXISTS %s', $table)); 26 $create = sprintf('CREATE TABLE %s(id INT)', $table); 27 $db->exec($create); 28 $db->exec(sprintf('INSERT INTO %s(id) VALUES (1)', $table)); 29 $stmt = $db->query(sprintf('SELECT * FROM %s; INSERT INTO %s(id) VALUES (2)', $table, $table)); 30 $stmt->closeCursor(); 31 $info = $db->errorInfo(); 32 var_dump($info[0]); 33 $stmt = $db->query(sprintf('SELECT id FROM %s', $table)); 34 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 35 // A single query with a trailing delimiter. 36 $stmt = $db->query('SELECT 1 AS value;'); 37 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 38 39 // New connection, does not allow multiple statements. 40 $db = new PDO($dsn, $user, $pass, array(PDO::MYSQL_ATTR_MULTI_STATEMENTS => false)); 41 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); 42 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 43 $stmt = $db->query(sprintf('SELECT * FROM %s; INSERT INTO %s(id) VALUES (3)', $table, $table)); 44 var_dump($stmt); 45 $info = $db->errorInfo(); 46 var_dump($info[0]); 47 48 $stmt = $db->query(sprintf('SELECT id FROM %s', $table)); 49 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 50 // A single query with a trailing delimiter. 51 $stmt = $db->query('SELECT 1 AS value;'); 52 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 53 54 $db->exec(sprintf('DROP TABLE IF EXISTS %s', $table)); 55 print "done!"; 56?> 57--EXPECTF-- 58string(5) "00000" 59array(2) { 60 [0]=> 61 array(1) { 62 ["id"]=> 63 string(1) "1" 64 } 65 [1]=> 66 array(1) { 67 ["id"]=> 68 string(1) "2" 69 } 70} 71array(1) { 72 [0]=> 73 array(1) { 74 ["value"]=> 75 string(1) "1" 76 } 77} 78 79Warning: PDO::query(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'INSERT INTO %s(id) VALUES (3)' at line 1 in %s on line %d 80bool(false) 81string(5) "42000" 82array(2) { 83 [0]=> 84 array(1) { 85 ["id"]=> 86 string(1) "1" 87 } 88 [1]=> 89 array(1) { 90 ["id"]=> 91 string(1) "2" 92 } 93} 94array(1) { 95 [0]=> 96 array(1) { 97 ["value"]=> 98 string(1) "1" 99 } 100} 101done! 102