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