1--TEST-- 2PDO Common: PDO::FETCH_KEY_PAIR fetch mode test 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 (a varchar(100), b varchar(100), c varchar(100))"); 19 20for ($i = 0; $i < 5; $i++) { 21 $db->exec("INSERT INTO test (a,b,c) VALUES('test".$i."','".$i."','".$i."')"); 22} 23 24var_dump($db->query("SELECT a,b FROM test")->fetch(PDO::FETCH_KEY_PAIR)); 25var_dump($db->query("SELECT a,b FROM test")->fetchAll(PDO::FETCH_KEY_PAIR)); 26var_dump($db->query("SELECT * FROM test")->fetch(PDO::FETCH_KEY_PAIR)); 27var_dump($db->query("SELECT a,a FROM test")->fetchAll(PDO::FETCH_KEY_PAIR)); 28 29?> 30--EXPECTF-- 31array(1) { 32 ["test0"]=> 33 string(1) "0" 34} 35array(5) { 36 ["test0"]=> 37 string(1) "0" 38 ["test1"]=> 39 string(1) "1" 40 ["test2"]=> 41 string(1) "2" 42 ["test3"]=> 43 string(1) "3" 44 ["test4"]=> 45 string(1) "4" 46} 47 48Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error: PDO::FETCH_KEY_PAIR fetch mode requires the result set to contain exactly 2 columns. in %spdo_034.php on line %d 49 50Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error%spdo_034.php on line %d 51bool(false) 52array(5) { 53 ["test0"]=> 54 string(5) "test0" 55 ["test1"]=> 56 string(5) "test1" 57 ["test2"]=> 58 string(5) "test2" 59 ["test3"]=> 60 string(5) "test3" 61 ["test4"]=> 62 string(5) "test4" 63} 64