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