Annotation of embedaddon/php/ext/pdo_mysql/tests/pdo_mysql_prepare_emulated_placeholder_everywhere.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: MySQL PDO->prepare(), emulated PS, anonymous placeholder
3: --SKIPIF--
4: <?php
5: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7: MySQLPDOTest::skip();
8: // TODO: This test is MySQL version specific - for whatever reason
9: ?>
10: --FILE--
11: <?php
12: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13: $db = MySQLPDOTest::factory();
14:
15: try {
16: // native PS
17: $db->setAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY, 0);
18: if (0 != $db->getAttribute(PDO::MYSQL_ATTR_DIRECT_QUERY))
19: printf("[002] Unable to switch off emulated prepared statements, test will fail\n");
20:
21: $db->exec('DROP TABLE IF EXISTS test');
22: $db->exec(sprintf('CREATE TABLE test(id INT, label CHAR(255)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
23: $db->exec("INSERT INTO test(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 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 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
59: require dirname(__FILE__) . '/mysql_pdo_test.inc';
60: $db = MySQLPDOTest::factory();
61: $db->exec('DROP TABLE IF EXISTS test');
62: ?>
63: --EXPECTF--
64: Warning: 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: )
70: array(0) {
71: }
72: now the same with emulated PS
73:
74: Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in %s on line %d
75:
76: Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in %s on line 33
77: [005] Execute has failed, 'HY093' array (
78: 0 => 'HY093',
79: 1 => NULL,
80: 2 => NULL,
81: )
82: array(0) {
83: }
84: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>