1--TEST-- 2PDO Common: PDOStatement iterator 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 test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10))'); 19$db->exec('INSERT INTO test VALUES(1, \'A\', \'Group1\')'); 20$db->exec('INSERT INTO test VALUES(2, \'B\', \'Group2\')'); 21 22$SELECT = 'SELECT val, grp FROM test'; 23 24$stmt = $db->prepare($SELECT); 25 26$stmt->execute(); 27$stmt->setFetchMode(PDO::FETCH_NUM); 28foreach ($stmt as $data) 29{ 30 var_dump($data); 31} 32 33class Test 34{ 35 public $val; 36 public $grp; 37 38 function __construct($name = 'N/A') 39 { 40 echo __METHOD__ . "($name)\n"; 41 } 42} 43 44unset($stmt); 45 46foreach ($db->query($SELECT, PDO::FETCH_CLASS, 'Test') as $data) 47{ 48 var_dump($data); 49} 50 51unset($stmt); 52 53$stmt = $db->query($SELECT, PDO::FETCH_CLASS, 'Test', array('WOW')); 54 55foreach($stmt as $data) 56{ 57 var_dump($data); 58} 59?> 60--EXPECTF-- 61array(2) { 62 [0]=> 63 string(1) "A" 64 [1]=> 65 string(6) "Group1" 66} 67array(2) { 68 [0]=> 69 string(1) "B" 70 [1]=> 71 string(6) "Group2" 72} 73Test::__construct(N/A) 74object(Test)#%d (2) { 75 ["val"]=> 76 string(1) "A" 77 ["grp"]=> 78 string(6) "Group1" 79} 80Test::__construct(N/A) 81object(Test)#%d (2) { 82 ["val"]=> 83 string(1) "B" 84 ["grp"]=> 85 string(6) "Group2" 86} 87Test::__construct(WOW) 88object(Test)#%d (2) { 89 ["val"]=> 90 string(1) "A" 91 ["grp"]=> 92 string(6) "Group1" 93} 94Test::__construct(WOW) 95object(Test)#%d (2) { 96 ["val"]=> 97 string(1) "B" 98 ["grp"]=> 99 string(6) "Group2" 100} 101