1--TEST--
2MySQL PDOStatement->errorCode();
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--FILE--
11<?php
12    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13    $db = MySQLPDOTest::factory();
14
15    $db->exec('DROP TABLE IF EXISTS ihopeitdoesnotexist');
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        $stmt->execute();
25        var_dump($stmt->errorCode());
26
27
28    } catch (PDOException $e) {
29        printf("[001] %s [%s] %s\n",
30            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
31    }
32
33    printf("Testing native PS...\n");
34    try {
35        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
36        if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
37            printf("[004] Unable to turn off emulated prepared statements\n");
38
39        $stmt = $db->prepare('SELECT id FROM ihopeitdoesnotexist ORDER BY id ASC');
40        $stmt->execute();
41        var_dump($stmt->errorCode());
42
43    } catch (PDOException $e) {
44        printf("[003] %s [%s] %s\n",
45            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
46    }
47
48    print "done!";
49?>
50--EXPECTF--
51Testing emulated PS...
52
53Warning: PDOStatement::execute(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.ihopeitdoesnotexist' doesn't exist in %s on line %d
54string(5) "42S02"
55Testing native PS...
56
57Warning: PDO::prepare(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.ihopeitdoesnotexist' doesn't exist in %s on line %d
58
59Fatal error: Uncaught Error: Call to a member function execute() on bool in %s:%d
60Stack trace:
61#0 {main}
62  thrown in %s on line %d
63