1--TEST--
2MySQL PDO->prepare(), native PS, clear line after error
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    try {
16
17        $db->exec('DROP TABLE IF EXISTS test');
18        $db->exec(sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
19
20        // We need to run the emulated version first. Native version will cause a fatal error
21        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
22        if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
23            printf("[002] Unable to turn on emulated prepared statements\n");
24
25        // INSERT a single row
26        $db->exec("INSERT INTO test(id, label) VALUES (1, 'row1')");
27
28        $stmt = $db->prepare('SELECT unknown_column FROM test WHERE id > :placeholder ORDER BY id ASC');
29        $stmt->execute(array(':placeholder' => 0));
30        if ('00000' !== $stmt->errorCode())
31            printf("[003] Execute has failed, %s %s\n",
32                var_export($stmt->errorCode(), true),
33                var_export($stmt->errorInfo(), true));
34
35        $stmt = $db->prepare('SELECT id, label FROM test WHERE id > :placeholder ORDER BY id ASC');
36        $stmt->execute(array(':placeholder' => 0));
37        if ('00000' !== $stmt->errorCode())
38            printf("[004] Execute has failed, %s %s\n",
39                var_export($stmt->errorCode(), true),
40                var_export($stmt->errorInfo(), true));
41        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
42
43        // Native PS
44        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
45        if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
46            printf("[005] Unable to turn off emulated prepared statements\n");
47
48        $stmt = $db->prepare('SELECT unknown_column FROM test WHERE id > :placeholder ORDER BY id ASC');
49        $stmt->execute(array(':placeholder' => 0));
50        if ('00000' !== $stmt->errorCode())
51            printf("[006] Execute has failed, %s %s\n",
52                var_export($stmt->errorCode(), true),
53                var_export($stmt->errorInfo(), true));
54
55        $stmt = $db->prepare('SELECT id, label FROM test WHERE id > :placeholder ORDER BY id ASC');
56        $stmt->execute(array(':placeholder' => 0));
57        if ('00000' !== $stmt->errorCode())
58            printf("[007] Execute has failed, %s %s\n",
59                var_export($stmt->errorCode(), true),
60                var_export($stmt->errorInfo(), true));
61        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
62
63
64    } catch (PDOException $e) {
65        printf("[001] %s [%s] %s\n",
66            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
67    }
68
69    print "done!";
70?>
71--CLEAN--
72<?php
73require __DIR__ . '/mysql_pdo_test.inc';
74$db = MySQLPDOTest::factory();
75$db->exec('DROP TABLE IF EXISTS test');
76?>
77--EXPECTF--
78Warning: PDOStatement::execute(): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'unknown_column' in 'field list' in %s on line %d
79[003] Execute has failed, '42S22' array (
80  0 => '42S22',
81  1 => 1054,
82  2 => 'Unknown column \'unknown_column\' in \'field list\'',
83)
84array(1) {
85  [0]=>
86  array(2) {
87    ["id"]=>
88    string(1) "1"
89    ["label"]=>
90    string(4) "row1"
91  }
92}
93
94Warning: PDO::prepare(): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'unknown_column' in 'field list' in %s on line %d
95
96Fatal error: Uncaught Error: Call to a member function execute() on bool in %s:%d
97Stack trace:
98#0 {main}
99  thrown in %s on line %d
100