1--TEST-- 2PDO Common: PDOStatement::setFetchMode 3--EXTENSIONS-- 4pdo 5--SKIPIF-- 6<?php 7$dir = getenv('REDIR_TEST_DIR'); 8if (false == $dir) die('skip no driver'); 9require_once $dir . 'pdo_test.inc'; 10PDOTest::skip(); 11?> 12--FILE-- 13<?php 14if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/'); 15require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 16$db = PDOTest::factory(); 17 18$db->exec('CREATE TABLE test012(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10))'); 19$db->exec("INSERT INTO test012 VALUES(1, 'A', 'Group1')"); 20$db->exec("INSERT INTO test012 VALUES(2, 'B', 'Group2')"); 21 22$SELECT = 'SELECT val, grp FROM test012'; 23 24$stmt = $db->query($SELECT, PDO::FETCH_NUM); 25var_dump($stmt->fetchAll()); 26 27class TestClass 28{ 29 public $val; 30 public $grp; 31 32 function __construct($name = 'N/A') 33 { 34 echo __METHOD__ . "($name)\n"; 35 } 36} 37 38unset($stmt); 39 40$stmt = $db->query($SELECT, PDO::FETCH_CLASS, TestClass::class); 41var_dump($stmt->fetchAll()); 42 43unset($stmt); 44 45$stmt = $db->query($SELECT, PDO::FETCH_NUM); 46$stmt->setFetchMode(PDO::FETCH_CLASS, TestClass::class, array('Changed')); 47var_dump($stmt->fetchAll()); 48 49?> 50--CLEAN-- 51<?php 52require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 53$db = PDOTest::factory(); 54PDOTest::dropTableIfExists($db, "test012"); 55?> 56--EXPECTF-- 57array(2) { 58 [0]=> 59 array(2) { 60 [0]=> 61 string(1) "A" 62 [1]=> 63 string(6) "Group1" 64 } 65 [1]=> 66 array(2) { 67 [0]=> 68 string(1) "B" 69 [1]=> 70 string(6) "Group2" 71 } 72} 73TestClass::__construct(N/A) 74TestClass::__construct(N/A) 75array(2) { 76 [0]=> 77 object(TestClass)#%d (2) { 78 ["val"]=> 79 string(1) "A" 80 ["grp"]=> 81 string(6) "Group1" 82 } 83 [1]=> 84 object(TestClass)#%d (2) { 85 ["val"]=> 86 string(1) "B" 87 ["grp"]=> 88 string(6) "Group2" 89 } 90} 91TestClass::__construct(Changed) 92TestClass::__construct(Changed) 93array(2) { 94 [0]=> 95 object(TestClass)#%d (2) { 96 ["val"]=> 97 string(1) "A" 98 ["grp"]=> 99 string(6) "Group1" 100 } 101 [1]=> 102 object(TestClass)#%d (2) { 103 ["val"]=> 104 string(1) "B" 105 ["grp"]=> 106 string(6) "Group2" 107 } 108} 109