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