1--TEST--
2mysqli_fetch_assoc() - ZEROFILL
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once('connect.inc');
11    require_once('table.inc');
12
13    function zerofill($offset, $link, $datatype, $insert = 1) {
14
15        mysqli_query($link, 'ALTER TABLE test DROP zero');
16        $sql = sprintf('ALTER TABLE test ADD zero %s UNSIGNED ZEROFILL', $datatype);
17        if (!mysqli_query($link, $sql)) {
18            // no worries - server might not support it
19            return true;
20        }
21
22        if (!mysqli_query($link, sprintf('UPDATE test SET zero = %s', $insert))) {
23            printf("[%03d] UPDATE failed, [%d] %s\n",
24                $offset, mysqli_errno($link), mysqli_error($link));
25            return false;
26        }
27
28        if (!($res = mysqli_query($link, 'SELECT zero FROM test LIMIT 1'))) {
29            printf("[%03d] SELECT failed, [%d] %s\n",
30                $offset, mysqli_errno($link), mysqli_error($link));
31            return false;
32        }
33
34        $row = mysqli_fetch_assoc($res);
35        $meta = mysqli_fetch_fields($res);
36        mysqli_free_result($res);
37        $meta = $meta[0];
38        $length = $meta->length;
39        if ($length > strlen($insert)) {
40
41            $expected = str_repeat('0', $length - strlen($insert));
42            $expected .= $insert;
43            if ($expected !== $row['zero']) {
44                printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $row['zero']);
45                return false;
46            }
47
48        } else if ($length <= 1) {
49            printf("[%03d] Length reported is too small to run test\n", $offset);
50            return false;
51        }
52
53        return true;
54    }
55
56    zerofill(2, $link, 'TINYINT');
57    zerofill(3, $link, 'SMALLINT');
58    zerofill(4, $link, 'MEDIUMINT');
59    zerofill(5, $link, 'INT');
60    zerofill(6, $link, 'INTEGER');
61    zerofill(7, $link, 'BIGINT');
62    zerofill(8, $link, 'FLOAT');
63    zerofill(9, $link, 'DOUBLE');
64    zerofill(10, $link, 'DOUBLE PRECISION');
65    zerofill(11, $link, 'DECIMAL');
66    zerofill(12, $link, 'DEC');
67
68    mysqli_close($link);
69
70    print "done!";
71?>
72--CLEAN--
73<?php
74    require_once("clean_table.inc");
75?>
76--EXPECT--
77done!
78