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