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