1--TEST-- 2PDO Common: fetch() and while() 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(idx int NOT NULL PRIMARY KEY, txt VARCHAR(20))'); 19$db->exec('INSERT INTO test VALUES(0, \'String0\')'); 20$db->exec('INSERT INTO test VALUES(1, \'String1\')'); 21$db->exec('INSERT INTO test VALUES(2, \'String2\')'); 22$db->exec('INSERT INTO test VALUES(3, \'String3\')'); 23 24 25var_dump($db->query('SELECT COUNT(*) FROM test')->fetchColumn()); 26 27$stmt = $db->prepare('SELECT idx, txt FROM test ORDER by idx'); 28 29$stmt->execute(); 30$cont = $stmt->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); 31var_dump($cont); 32 33echo "===WHILE===\n"; 34 35$stmt->bindColumn('idx', $idx); 36$stmt->bindColumn('txt', $txt); 37$stmt->execute(); 38 39while($stmt->fetch(PDO::FETCH_BOUND)) { 40 var_dump(array($idx=>$txt)); 41} 42 43?> 44--EXPECT-- 45string(1) "4" 46array(4) { 47 [0]=> 48 string(7) "String0" 49 [1]=> 50 string(7) "String1" 51 [2]=> 52 string(7) "String2" 53 [3]=> 54 string(7) "String3" 55} 56===WHILE=== 57array(1) { 58 [0]=> 59 string(7) "String0" 60} 61array(1) { 62 [1]=> 63 string(7) "String1" 64} 65array(1) { 66 [2]=> 67 string(7) "String2" 68} 69array(1) { 70 [3]=> 71 string(7) "String3" 72} 73