xref: /php-src/ext/pdo/tests/pdo_034.phpt (revision f4a5db3e)
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 test034 (a varchar(100), b varchar(100), c varchar(100))");
19
20for ($i = 0; $i < 5; $i++) {
21    $db->exec("INSERT INTO test034 (a,b,c) VALUES('test".$i."','".$i."','".$i."')");
22}
23
24var_dump($db->query("SELECT a,b FROM test034")->fetch(PDO::FETCH_KEY_PAIR));
25var_dump($db->query("SELECT a,b FROM test034")->fetchAll(PDO::FETCH_KEY_PAIR));
26var_dump($db->query("SELECT * FROM test034")->fetch(PDO::FETCH_KEY_PAIR));
27var_dump($db->query("SELECT a,a FROM test034")->fetchAll(PDO::FETCH_KEY_PAIR));
28
29?>
30--CLEAN--
31<?php
32require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
33$db = PDOTest::factory();
34PDOTest::dropTableIfExists($db, "test034");
35?>
36--EXPECTF--
37array(1) {
38  ["test0"]=>
39  string(1) "0"
40}
41array(5) {
42  ["test0"]=>
43  string(1) "0"
44  ["test1"]=>
45  string(1) "1"
46  ["test2"]=>
47  string(1) "2"
48  ["test3"]=>
49  string(1) "3"
50  ["test4"]=>
51  string(1) "4"
52}
53
54Warning: 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
55
56Warning: PDOStatement::fetch(): SQLSTATE[HY000]: General error%spdo_034.php on line %d
57bool(false)
58array(5) {
59  ["test0"]=>
60  string(5) "test0"
61  ["test1"]=>
62  string(5) "test1"
63  ["test2"]=>
64  string(5) "test2"
65  ["test3"]=>
66  string(5) "test3"
67  ["test4"]=>
68  string(5) "test4"
69}
70