1--TEST--
2mysqli_options() - MYSQLI_OPT_INT_AND_FLOAT_NATIVE
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    require_once 'connect.inc';
12
13
14    $types = array(
15        'BIT' 			=> array('BIT(8)', 0),
16        'TINYINT'		=> array('TINYINT', 120),
17        'BOOL'			=> array('BOOL', 0),
18        'BOOLEAN'		=> array('BOOLEAN', 1),
19        'SMALLINT'		=> array('SMALLINT', 32000),
20        'MEDIUMINT'		=> array('MEDIUMINT', 999),
21        'INT'			=> array('INT', 999),
22        'BIGINT'		=> array('BIGINT', 999),
23        'FLOAT'			=> array('FLOAT', 1.3),
24        'DOUBLE'		=> array('DOUBLE', -1.3),
25    );
26
27    foreach ($types as $name => $data) {
28        $link = mysqli_init();
29        if (!mysqli_options($link, MYSQLI_OPT_INT_AND_FLOAT_NATIVE, 1)) {
30            printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
31            continue;
32        }
33
34        if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) {
35            printf("[002] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
36            continue;
37        }
38
39
40        if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
41            printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
42            continue;
43        }
44
45        if (!mysqli_query($link, sprintf("CREATE TABLE test (id %s)", $data[0]))) {
46            printf("[004] TODO [%d] %s\n", mysqli_errno($link), mysqli_error($link));
47            continue;
48        }
49
50        if (!mysqli_query($link, sprintf("INSERT INTO test(id) VALUES (%f)", $data[1]))) {
51            printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
52            continue;
53        }
54
55        if (!$res = mysqli_query($link, "SELECT id FROM test")) {
56            printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57            continue;
58        }
59
60        $row = mysqli_fetch_assoc($res);
61        mysqli_free_result($res);
62
63        if ($row['id'] !== $data[1]) {
64            printf("[007] Expecting %s - %s/%s got %s/%s\n",
65                $name,
66                $data[1], gettype($data[1]), $row['id'], gettype($row['id']));
67        }
68        mysqli_close($link);
69
70        $link = mysqli_init();
71        if (!mysqli_options($link, MYSQLI_OPT_INT_AND_FLOAT_NATIVE, 0)) {
72            printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
73            continue;
74        }
75
76        if (!my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket)) {
77            printf("[009] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
78            continue;
79        }
80
81        if (!$res = mysqli_query($link, "SELECT id FROM test")) {
82            printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
83            continue;
84        }
85
86        $row = mysqli_fetch_assoc($res);
87        mysqli_free_result($res);
88
89        if (!is_string($row['id']) || ($row['id'] != $data[1])) {
90            printf("[011] Expecting %s - %s/string got %s/%s\n",
91                $name,
92                $data[1], $row['id'], gettype($row['id']));
93        }
94        mysqli_close($link);
95
96    }
97
98    print "done!";
99?>
100--CLEAN--
101<?php
102require_once 'clean_table.inc';
103?>
104--EXPECT--
105done!
106