1--TEST--
2MySQL PDOStatement->fetch()
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12    require_once __DIR__ . '/inc/mysql_pdo_test.inc';
13    $db = MySQLPDOTest::factory();
14
15    function fetch($offset, &$db, $query, $expect = null) {
16        try {
17            $stmt = $db->query('SELECT 1');
18            $num = $stmt->fetch(PDO::FETCH_NUM);
19
20            $stmt = $db->query('SELECT 1');
21            $assoc = $stmt->fetch(PDO::FETCH_ASSOC);
22
23            $stmt = $db->query('SELECT 1');
24            $both = $stmt->fetch(PDO::FETCH_BOTH);
25
26            $computed_both = array_merge($num, $assoc);
27            if ($computed_both != $both) {
28                printf("[%03d] Suspicious FETCH_BOTH result, dumping\n", $offset);
29                var_dump($computed_both);
30                var_dump($both);
31            }
32
33            if (!is_null($expect) && ($expect != $both)) {
34                printf("[%03d] Expected differs from returned data, dumping\n", $offset);
35                var_dump($expect);
36                var_dump($both);
37            }
38        } catch (PDOException $e) {
39            printf("[%03d] %s, [%s] %s\n",
40                $offset,
41                $e->getMessage(), $db->errroCode(), implode(' ', $db->errorInfo()));
42        }
43    }
44
45    try {
46        fetch(2, $db, 'SELECT 1', array(0 => '1', '1' => '1'));
47    } catch (PDOException $e) {
48        printf("[001] %s [%s] %s\n",
49            $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
50    }
51
52    print "done!";
53?>
54--EXPECT--
55done!
56