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