1--TEST-- 2PDO Common: PDO::FETCH_CLASSTYPE 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 classtypes009(id int NOT NULL PRIMARY KEY, name VARCHAR(10) NOT NULL UNIQUE)'); 19$db->exec("INSERT INTO classtypes009 VALUES(0, 'stdClass')"); 20$db->exec("INSERT INTO classtypes009 VALUES(1, 'Test1')"); 21$db->exec("INSERT INTO classtypes009 VALUES(2, 'Test2')"); 22$db->exec('CREATE TABLE test009(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(10))'); 23$db->exec("INSERT INTO test009 VALUES(1, 0, 'A')"); 24$db->exec("INSERT INTO test009 VALUES(2, 1, 'B')"); 25$db->exec("INSERT INTO test009 VALUES(3, 2, 'C')"); 26$db->exec("INSERT INTO test009 VALUES(4, 3, 'D')"); 27 28$stmt = $db->prepare('SELECT classtypes009.name, test009.id AS id, test009.val AS val FROM test009 LEFT JOIN classtypes009 ON test009.classtype=classtypes009.id'); 29 30class Test1 31{ 32 public $id; 33 public $val; 34 35 public function __construct() 36 { 37 echo __METHOD__ . "()\n"; 38 } 39} 40 41class Test2 42{ 43 public $id; 44 public $val; 45 46 public function __construct() 47 { 48 echo __METHOD__ . "()\n"; 49 } 50} 51 52class Test3 53{ 54 public $id; 55 public $val; 56 57 public function __construct() 58 { 59 echo __METHOD__ . "()\n"; 60 } 61} 62 63$stmt->execute(); 64var_dump($stmt->fetchAll(PDO::FETCH_NUM)); 65 66$stmt->execute(); 67var_dump($stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE, 'Test3')); 68 69?> 70--CLEAN-- 71<?php 72require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 73$db = PDOTest::factory(); 74PDOTest::dropTableIfExists($db, "test009"); 75PDOTest::dropTableIfExists($db, "classtypes009"); 76?> 77--EXPECTF-- 78array(4) { 79 [0]=> 80 array(3) { 81 [0]=> 82 string(8) "stdClass" 83 [1]=> 84 string(1) "1" 85 [2]=> 86 string(1) "A" 87 } 88 [1]=> 89 array(3) { 90 [0]=> 91 string(5) "Test1" 92 [1]=> 93 string(1) "2" 94 [2]=> 95 string(1) "B" 96 } 97 [2]=> 98 array(3) { 99 [0]=> 100 string(5) "Test2" 101 [1]=> 102 string(1) "3" 103 [2]=> 104 string(1) "C" 105 } 106 [3]=> 107 array(3) { 108 [0]=> 109 NULL 110 [1]=> 111 string(1) "4" 112 [2]=> 113 string(1) "D" 114 } 115} 116Test1::__construct() 117Test2::__construct() 118Test3::__construct() 119array(4) { 120 [0]=> 121 object(stdClass)#%d (2) { 122 ["id"]=> 123 string(1) "1" 124 ["val"]=> 125 string(1) "A" 126 } 127 [1]=> 128 object(Test1)#%d (2) { 129 ["id"]=> 130 string(1) "2" 131 ["val"]=> 132 string(1) "B" 133 } 134 [2]=> 135 object(Test2)#%d (2) { 136 ["id"]=> 137 string(1) "3" 138 ["val"]=> 139 string(1) "C" 140 } 141 [3]=> 142 object(Test3)#%d (2) { 143 ["id"]=> 144 string(1) "4" 145 ["val"]=> 146 string(1) "D" 147 } 148} 149