1--TEST-- 2PDO Common: PDO::FETCH_CLASSTYPE and GROUP/UNIQUE 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 classtypes010(id int NOT NULL PRIMARY KEY, name VARCHAR(10) NOT NULL UNIQUE)'); 19$db->exec("INSERT INTO classtypes010 VALUES(0, 'stdClass')"); 20$db->exec("INSERT INTO classtypes010 VALUES(1, 'Test1')"); 21$db->exec("INSERT INTO classtypes010 VALUES(2, 'Test2')"); 22$db->exec('CREATE TABLE test010(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(10), grp VARCHAR(10))'); 23$db->exec("INSERT INTO test010 VALUES(1, 0, 'A', 'Group1')"); 24$db->exec("INSERT INTO test010 VALUES(2, 1, 'B', 'Group1')"); 25$db->exec("INSERT INTO test010 VALUES(3, 2, 'C', 'Group2')"); 26$db->exec("INSERT INTO test010 VALUES(4, 3, 'D', 'Group2')"); 27 28$stmt = $db->prepare('SELECT classtypes010.name, test010.grp AS grp, test010.id AS id, test010.val AS val FROM test010 LEFT JOIN classtypes010 ON test010.classtype=classtypes010.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 64$stmt->execute(); 65var_dump($stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_GROUP, 'Test3')); 66 67$stmt->execute(); 68var_dump($stmt->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_UNIQUE, 'Test3')); 69 70?> 71--CLEAN-- 72<?php 73require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 74$db = PDOTest::factory(); 75PDOTest::dropTableIfExists($db, "test010"); 76PDOTest::dropTableIfExists($db, "classtypes010"); 77?> 78--EXPECTF-- 79Test1::__construct() 80Test2::__construct() 81Test3::__construct() 82array(2) { 83 ["Group1"]=> 84 array(2) { 85 [0]=> 86 object(stdClass)#%d (2) { 87 ["id"]=> 88 string(1) "1" 89 ["val"]=> 90 string(1) "A" 91 } 92 [1]=> 93 object(Test1)#%d (2) { 94 ["id"]=> 95 string(1) "2" 96 ["val"]=> 97 string(1) "B" 98 } 99 } 100 ["Group2"]=> 101 array(2) { 102 [0]=> 103 object(Test2)#%d (2) { 104 ["id"]=> 105 string(1) "3" 106 ["val"]=> 107 string(1) "C" 108 } 109 [1]=> 110 object(Test3)#%d (2) { 111 ["id"]=> 112 string(1) "4" 113 ["val"]=> 114 string(1) "D" 115 } 116 } 117} 118Test1::__construct() 119Test2::__construct() 120Test3::__construct() 121array(2) { 122 ["Group1"]=> 123 object(Test1)#%d (2) { 124 ["id"]=> 125 string(1) "2" 126 ["val"]=> 127 string(1) "B" 128 } 129 ["Group2"]=> 130 object(Test3)#%d (2) { 131 ["id"]=> 132 string(1) "4" 133 ["val"]=> 134 string(1) "D" 135 } 136} 137