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