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