1--TEST--
2MySQL PDOStatement->fetch()
3--SKIPIF--
4<?php
5require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8$db = MySQLPDOTest::factory();
9?>
10--FILE--
11<?php
12    require_once(__DIR__ . 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 differs 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--EXPECT--
62done!
63