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