1--TEST-- 2PDO Common: PDO::FETCH_KEY_PAIR fetch mode test 3--SKIPIF-- 4<?php # vim:ft=php 5if (!extension_loaded('pdo')) die('skip'); 6$dir = getenv('REDIR_TEST_DIR'); 7if (false == $dir) die('skip no driver'); 8require_once $dir . 'pdo_test.inc'; 9PDOTest::skip(); 10?> 11--FILE-- 12<?php 13if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/'); 14require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; 15$db = PDOTest::factory(); 16 17$db->exec("CREATE TABLE test (a varchar(100), b varchar(100), c varchar(100))"); 18 19for ($i = 0; $i < 5; $i++) { 20 $db->exec("INSERT INTO test (a,b,c) VALUES('test".$i."','".$i."','".$i."')"); 21} 22 23var_dump($db->query("SELECT a,b FROM test")->fetch(PDO::FETCH_KEY_PAIR)); 24var_dump($db->query("SELECT a,b FROM test")->fetchAll(PDO::FETCH_KEY_PAIR)); 25var_dump($db->query("SELECT * FROM test")->fetch(PDO::FETCH_KEY_PAIR)); 26var_dump($db->query("SELECT a,a FROM test")->fetchAll(PDO::FETCH_KEY_PAIR)); 27 28?> 29--EXPECTF-- 30array(1) { 31 ["test0"]=> 32 string(1) "0" 33} 34array(5) { 35 ["test0"]=> 36 string(1) "0" 37 ["test1"]=> 38 string(1) "1" 39 ["test2"]=> 40 string(1) "2" 41 ["test3"]=> 42 string(1) "3" 43 ["test4"]=> 44 string(1) "4" 45} 46 47Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error: PDO::FETCH_KEY_PAIR fetch mode requires the result set to contain extactly 2 columns. in %spdo_034.php on line %d 48 49Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error%spdo_034.php on line %d 50bool(false) 51array(5) { 52 ["test0"]=> 53 string(5) "test0" 54 ["test1"]=> 55 string(5) "test1" 56 ["test2"]=> 57 string(5) "test2" 58 ["test3"]=> 59 string(5) "test3" 60 ["test4"]=> 61 string(5) "test4" 62} 63