1--TEST--
2MySQL PDO->prepare(), emulated PS, anonymous 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		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
17		if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
18			printf("[002] Unable to switch to emulated prepared statements, test will fail\n");
19
20		$db->exec('DROP TABLE IF EXISTS test');
21		$db->exec(sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
22
23		$stmt = $db->prepare("INSERT INTO test(id, label) VALUES(1, '?')");
24		// you can bind as many values as you want no matter if they can be replaced or not
25		$stmt->execute(array('first row'));
26		if ('00000' !== $stmt->errorCode())
27			printf("[003] Execute has failed, %s %s\n",
28				var_export($stmt->errorCode(), true),
29				var_export($stmt->errorInfo(), true));
30
31		$stmt = $db->prepare('SELECT id, label FROM test');
32		$stmt->execute();
33		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
34
35		// now the same with native PS
36		printf("now the same with native PS\n");
37		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
38		if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
39			printf("[004] Unable to switch off emulated prepared statements, test will fail\n");
40
41		$db->exec('DELETE FROM test');
42		$stmt = $db->prepare("INSERT INTO test(id, label) VALUES(1, '?')");
43		// you can bind as many values as you want no matter if they can be replaced or not
44		$stmt->execute(array('first row'));
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
50		$stmt = $db->prepare('SELECT id, label FROM test');
51		$stmt->execute();
52		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
53
54	} catch (PDOException $e) {
55		printf("[001] %s [%s] %s\n",
56			$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
57	}
58
59	print "done!";
60?>
61--CLEAN--
62<?php
63require dirname(__FILE__) . '/mysql_pdo_test.inc';
64$db = MySQLPDOTest::factory();
65$db->exec('DROP TABLE IF EXISTS test');
66?>
67--EXPECTF--
68array(1) {
69  [0]=>
70  array(2) {
71    ["id"]=>
72    string(1) "1"
73    ["label"]=>
74    string(1) "?"
75  }
76}
77now the same with native PS
78[005] Execute has failed, 'HY093' array (
79  0 => 'HY093',
80  1 => NULL,
81  2 => NULL,
82)
83array(0) {
84}
85done!
86