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