1--TEST--
2MySQL PDO->prepare(),native PS, anonymous placeholder
3--SKIPIF--
4<?php
5require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8$db = MySQLPDOTest::factory();
9?>
10--FILE--
11<?php
12	require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13	$db = MySQLPDOTest::factory();
14	try {
15		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 1);
16		if (1 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
17			printf("[002] Unable to switch on emulated prepared statements, test will fail\n");
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		$db->exec("INSERT INTO test(id, label) VALUES (1, 'row1')");
22
23		$stmt = $db->prepare('SELECT ?, id, label FROM test WHERE ? = ? ORDER BY id ASC');
24		$stmt->execute(array('id', 'label', 'label'));
25		if ('00000' !== $stmt->errorCode())
26			printf("[003] Execute has failed, %s %s\n",
27				var_export($stmt->errorCode(), true),
28				var_export($stmt->errorInfo(), true));
29		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
30
31		// now the same with native PS
32		printf("now the same with native PS\n");
33		$db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
34		if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
35			printf("[004] Unable to switch off emulated prepared statements, test will fail\n");
36
37		$stmt = $db->prepare('SELECT ?, id, label FROM test WHERE ? = ? ORDER BY id ASC');
38		$stmt->execute(array('id', 'label', 'label'));
39		if ('00000' !== $stmt->errorCode())
40			printf("[005] Execute has failed, %s %s\n",
41				var_export($stmt->errorCode(), true),
42				var_export($stmt->errorInfo(), true));
43
44		$tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
45		if (!MySQLPDOTest::isPDOMySQLnd()) {
46			if (isset($tmp[0]['id'])) {
47				// libmysql should return a string here whereas mysqlnd returns a native int
48				if (gettype($tmp[0]['id']) == 'string')
49					// convert to int for the test output...
50					settype($tmp[0]['id'], 'integer');
51			}
52		}
53		var_dump($tmp);
54
55	} catch (PDOException $e) {
56		printf("[001] %s [%s] %s\n",
57			$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
58	}
59
60	print "done!";
61?>
62--CLEAN--
63<?php
64require __DIR__ . '/mysql_pdo_test.inc';
65$db = MySQLPDOTest::factory();
66$db->exec('DROP TABLE IF EXISTS test');
67?>
68--EXPECT--
69array(1) {
70  [0]=>
71  array(2) {
72    ["id"]=>
73    string(1) "1"
74    ["label"]=>
75    string(4) "row1"
76  }
77}
78now the same with native PS
79array(1) {
80  [0]=>
81  array(3) {
82    ["?"]=>
83    string(2) "id"
84    ["id"]=>
85    int(1)
86    ["label"]=>
87    string(4) "row1"
88  }
89}
90done!
91