1--TEST--
2MySQL PDO->prepare(), native PS, named placeholder
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8$db = MySQLPDOTest::factory();
9?>
10--FILE--
11<?php
12	require_once(dirname(__FILE__) . 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		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
21		if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
22			printf("[002] Unable to turn off emulated prepared statements\n");
23
24		// INSERT a single row
25		$stmt = $db->prepare("INSERT INTO test(id, label) VALUES (100, ':placeholder')");
26
27		// Yes, there is no placeholder to bind to and named placeholder
28		// do not work with MySQL native PS, but lets see what happens!
29		// The ':placeholder' is a string constant in the INSERT statement.
30		// I would expect to get an error message, but this is not what happens.
31		$stmt->execute(array(':placeholder' => 'row1'));
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		// Ok, what has happened: anything inserted into the DB?
38		$stmt = $db->prepare('SELECT id, label FROM test');
39		$stmt->execute();
40		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
41
42		// Now the same with emulated PS.
43		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
44		if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
45			printf("[004] Unable to turn on emulated prepared statements\n");
46
47		// Note that the "named placeholder" is enclosed by double quotes.
48		$stmt = $db->prepare("INSERT INTO test(id, label) VALUES(101, ':placeholder')");
49		// No replacement shall be made
50		$stmt->execute(array(':placeholder' => 'row1'));
51		// Again, I'd like to see an error message
52		if ('00000' !== $stmt->errorCode())
53			printf("[005] Execute has failed, %s %s\n",
54				var_export($stmt->errorCode(), true),
55				var_export($stmt->errorInfo(), true));
56
57		// Now, what do we have in the DB?
58		$stmt = $db->prepare('SELECT id, label FROM test ORDER BY id');
59		$stmt->execute();
60		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
61
62	} catch (PDOException $e) {
63		printf("[001] %s [%s] %s\n",
64			$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
65	}
66
67	print "done!";
68?>
69--CLEAN--
70<?php
71require dirname(__FILE__) . '/mysql_pdo_test.inc';
72$db = MySQLPDOTest::factory();
73$db->exec('DROP TABLE IF EXISTS test');
74?>
75--EXPECT--
76[003] Execute has failed, 'HY093' array (
77  0 => 'HY093',
78  1 => NULL,
79  2 => NULL,
80)
81array(0) {
82}
83array(1) {
84  [0]=>
85  array(2) {
86    ["id"]=>
87    string(3) "101"
88    ["label"]=>
89    string(12) ":placeholder"
90  }
91}
92done!
93