1--TEST--
2MySQL PDOStatement->fetch()
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8$db = MySQLPDOTest::factory();
9?>
10--FILE--
11<?php
12	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13	$db = MySQLPDOTest::factory();
14
15	function fetch($offset, &$db, $query, $expect = null) {
16
17		try {
18			$stmt = $db->query('SELECT 1');
19			$num = $stmt->fetch(PDO::FETCH_NUM);
20
21			$stmt = $db->query('SELECT 1');
22			$assoc = $stmt->fetch(PDO::FETCH_ASSOC);
23
24			$stmt = $db->query('SELECT 1');
25			$both = $stmt->fetch(PDO::FETCH_BOTH);
26
27			$computed_both = array_merge($num, $assoc);
28			if ($computed_both != $both) {
29				printf("[%03d] Suspicious FETCH_BOTH result, dumping\n", $offset);
30				var_dump($computed_both);
31				var_dump($both);
32			}
33
34			if (!is_null($expect) && ($expect != $both)) {
35				printf("[%03d] Expected differes from returned data, dumping\n", $offset);
36				var_dump($expect);
37				var_dump($both);
38			}
39
40		} catch (PDOException $e) {
41
42			printf("[%03d] %s, [%s] %s\n",
43				$offset,
44				$e->getMessage(), $db->errroCode(), implode(' ', $db->errorInfo()));
45
46		}
47
48	}
49
50	try {
51
52		fetch(2, $db, 'SELECT 1', array(0 => '1', '1' => '1'));
53
54	} catch (PDOException $e) {
55		printf("[001] %s [%s] %s\n",
56			$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
57	}
58
59	print "done!";
60?>
61--EXPECTF--
62[002] Suspicious FETCH_BOTH result, dumping
63array(2) {
64  [0]=>
65  string(1) "1"
66  [1]=>
67  string(1) "1"
68}
69array(2) {
70  [1]=>
71  string(1) "1"
72  [2]=>
73  string(1) "1"
74}
75[002] Expected differes from returned data, dumping
76array(2) {
77  [0]=>
78  string(1) "1"
79  [1]=>
80  string(1) "1"
81}
82array(2) {
83  [1]=>
84  string(1) "1"
85  [2]=>
86  string(1) "1"
87}
88done!
89