1--TEST--
2PDOStatements and multi query
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13
14    function mysql_stmt_multiquery_wrong_usage($db) {
15
16        $stmt = $db->query('SELECT label FROM test ORDER BY id ASC LIMIT 1; SELECT label FROM test ORDER BY id ASC LIMIT 1');
17        var_dump($stmt->errorInfo());
18        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
19        var_dump($stmt->errorInfo());
20
21    }
22
23    function mysql_stmt_multiquery_proper_usage($db) {
24
25        $stmt = $db->query('SELECT label FROM test ORDER BY id ASC LIMIT 1; SELECT label FROM test ORDER BY id ASC LIMIT 1');
26        do {
27            var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
28        } while ($stmt->nextRowset());
29
30    }
31
32    try {
33
34        printf("Emulated Prepared Statements...\n");
35        $db = MySQLPDOTest::factory();
36        MySQLPDOTest::createTestTable($db);
37        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
38        mysql_stmt_multiquery_wrong_usage($db);
39        mysql_stmt_multiquery_proper_usage($db);
40
41        printf("Native Prepared Statements...\n");
42        $db = MySQLPDOTest::factory();
43        MySQLPDOTest::createTestTable($db);
44        $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
45        mysql_stmt_multiquery_wrong_usage($db);
46        mysql_stmt_multiquery_proper_usage($db);
47
48    } catch (PDOException $e) {
49        printf("[001] %s [%s] %s\n",
50            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
51    }
52
53    print "done!";
54?>
55--CLEAN--
56<?php
57require __DIR__ . '/mysql_pdo_test.inc';
58MySQLPDOTest::dropTestTable();
59?>
60--EXPECTF--
61Emulated Prepared Statements...
62array(3) {
63  [0]=>
64  string(5) "00000"
65  [1]=>
66  NULL
67  [2]=>
68  NULL
69}
70array(1) {
71  [0]=>
72  array(1) {
73    ["label"]=>
74    string(1) "a"
75  }
76}
77array(3) {
78  [0]=>
79  string(5) "00000"
80  [1]=>
81  NULL
82  [2]=>
83  NULL
84}
85array(1) {
86  [0]=>
87  array(1) {
88    ["label"]=>
89    string(1) "a"
90  }
91}
92array(1) {
93  [0]=>
94  array(1) {
95    ["label"]=>
96    string(1) "a"
97  }
98}
99Native Prepared Statements...
100
101Warning: 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 '%SSELECT label FROM test ORDER BY id ASC LIMIT 1' at line %d in %s on line %d
102
103Fatal error: Uncaught Error: Call to a member function errorInfo() on bool in %s:%d
104Stack trace:
105#0 %s(%d): mysql_stmt_multiquery_wrong_usage(Object(PDO))
106#1 {main}
107  thrown in %s on line %d
108