1--TEST--
2MySQL PDOStatement->errorInfo();
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--FILE--
12<?php
13    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14    $db = MySQLPDOTest::factory();
15    MySQLPDOTest::createTestTable($db);
16
17    printf("Testing emulated PS...\n");
18    try {
19        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
20        if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
21            printf("[002] Unable to turn on emulated prepared statements\n");
22
23        $stmt = $db->prepare('SELECT id FROM ihopeitdoesnotexist ORDER BY id ASC');
24        var_dump($stmt->errorInfo());
25        $stmt->execute();
26        var_dump($stmt->errorInfo());
27
28        MySQLPDOTest::createTestTable($db);
29        $stmt = $db->prepare('SELECT label FROM test ORDER BY id ASC LIMIT 1');
30        $db->exec('DROP TABLE test');
31        var_dump($stmt->execute());
32        var_dump($stmt->errorInfo());
33        var_dump($db->errorInfo());
34
35    } catch (PDOException $e) {
36        printf("[001] %s [%s] %s\n",
37            $e->getMessage(), $db->errorInfo(), implode(' ', $db->errorInfo()));
38    }
39
40    printf("Testing native PS...\n");
41    try {
42        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
43        if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
44            printf("[004] Unable to turn off emulated prepared statements\n");
45
46        $stmt = $db->prepare('SELECT id FROM ihopeitdoesnotexist ORDER BY id ASC');
47        var_dump($stmt);
48
49        MySQLPDOTest::createTestTable($db);
50        $stmt = $db->prepare('SELECT label FROM test ORDER BY id ASC LIMIT 1');
51        var_dump($stmt->errorInfo());
52        $db->exec('DROP TABLE test');
53        $stmt->execute();
54        var_dump($stmt->errorInfo());
55        var_dump($db->errorInfo());
56
57    } catch (PDOException $e) {
58        printf("[003] %s [%s] %s\n",
59            $e->getMessage(), $db->errorInfo(), implode(' ', $db->errorInfo()));
60    }
61    print "done!";
62?>
63--CLEAN--
64<?php
65require __DIR__ . '/mysql_pdo_test.inc';
66MySQLPDOTest::dropTestTable();
67?>
68--EXPECTF--
69Testing emulated PS...
70array(3) {
71  [0]=>
72  string(0) ""
73  [1]=>
74  NULL
75  [2]=>
76  NULL
77}
78
79Warning: PDOStatement::execute(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.ihopeitdoesnotexist' doesn't exist in %s on line %d
80array(3) {
81  [0]=>
82  string(5) "42S02"
83  [1]=>
84  int(1146)
85  [2]=>
86  string(%d) "Table '%s.ihopeitdoesnotexist' doesn't exist"
87}
88
89Warning: PDOStatement::execute(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.test' doesn't exist in %s on line %d
90bool(false)
91array(3) {
92  [0]=>
93  string(5) "42S02"
94  [1]=>
95  int(1146)
96  [2]=>
97  string(%d) "Table '%s.test' doesn't exist"
98}
99array(3) {
100  [0]=>
101  string(5) "00000"
102  [1]=>
103  NULL
104  [2]=>
105  NULL
106}
107Testing native PS...
108
109Warning: PDO::prepare(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.ihopeitdoesnotexist' doesn't exist in %s on line %d
110bool(false)
111array(3) {
112  [0]=>
113  string(0) ""
114  [1]=>
115  NULL
116  [2]=>
117  NULL
118}
119
120Warning: PDOStatement::execute(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.test' doesn't exist in %s on line %d
121array(3) {
122  [0]=>
123  string(5) "42S02"
124  [1]=>
125  int(1146)
126  [2]=>
127  string(%d) "Table '%s.test' doesn't exist"
128}
129array(3) {
130  [0]=>
131  string(5) "00000"
132  [1]=>
133  NULL
134  [2]=>
135  NULL
136}
137done!
138