1--TEST--
2MySQL PDO->prepare(), emulated PS, anonymous placeholder
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9// TODO: This test is MySQL version specific - for whatever reason
10?>
11--FILE--
12<?php
13    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14    $db = MySQLPDOTest::factory();
15
16    try {
17        // native PS
18        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
19        if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
20            printf("[002] Unable to switch off emulated prepared statements, test will fail\n");
21
22        $db->exec('DROP TABLE IF EXISTS test');
23        $db->exec(sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
24        $db->exec("INSERT INTO test(id, label) VALUES (1, 'row1')");
25
26        // So, what will happen? More placeholder but values and
27        // placeholders in interesting places...
28        $stmt = $db->prepare('SELECT ? FROM test WHERE ? > ?');
29        $stmt->execute(array('test'));
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        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
36
37        // now the same with emulated PS
38        printf("now the same with emulated PS\n");
39        $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
40        if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
41            printf("[004] Unable to switch on emulated prepared statements, test will fail\n");
42
43        $stmt = $db->prepare('SELECT ? FROM test WHERE ? > ?');
44        $stmt->execute(array('test'));
45        if ('00000' !== $stmt->errorCode())
46            printf("[005] Execute has failed, %s %s\n",
47                var_export($stmt->errorCode(), true),
48                var_export($stmt->errorInfo(), true));
49        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
50
51    } catch (PDOException $e) {
52        printf("[001] %s [%s] %s\n",
53            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
54    }
55
56    print "done!";
57?>
58--CLEAN--
59<?php
60require __DIR__ . '/mysql_pdo_test.inc';
61$db = MySQLPDOTest::factory();
62$db->exec('DROP TABLE IF EXISTS test');
63?>
64--EXPECTF--
65Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line %d
66[003] Execute has failed, 'HY093' array (
67  0 => 'HY093',
68  1 => NULL,
69  2 => NULL,
70)
71array(0) {
72}
73now the same with emulated PS
74
75Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in %s on line %d
76[005] Execute has failed, 'HY093' array (
77  0 => 'HY093',
78  1 => NULL,
79  2 => NULL,
80)
81array(0) {
82}
83done!
84