xref: /PHP-7.1/ext/mysqli/tests/bug52891.phpt (revision 113213f0)
1--TEST--
2Bug #52891 (Wrong data inserted with mysqli/mysqlnd when using bind_param,value > LONG_MAX)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7if (!$IS_MYSQLND) {
8	die("skip: test applies only to mysqlnd");
9}
10?>
11--FILE--
12<?php
13	require_once("connect.inc");
14
15	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
16		printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
17	}
18
19	if (!$link->query("DROP TABLE IF EXISTS tuint") ||
20		!$link->query("DROP TABLE IF EXISTS tsint")) {
21		printf("[002] [%d] %s\n", $link->errno, $link->error);
22	}
23
24	if (!$link->query("CREATE TABLE tuint(a BIGINT UNSIGNED) ENGINE=" . $engine) ||
25		!$link->query("CREATE TABLE tsint(a BIGINT) ENGINE=" . $engine)) {
26		printf("[003] [%d] %s\n", $link->errno, $link->error);
27	}
28
29
30	if (!$stmt1 = $link->prepare("INSERT INTO tuint VALUES(?)"))
31		printf("[004] [%d] %s\n", $link->errno, $link->error);
32
33	if (!$stmt2 = $link->prepare("INSERT INTO tsint VALUES(?)"))
34		printf("[005] [%d] %s\n", $link->errno, $link->error);
35
36	$param = 42;
37
38	if (!$stmt1->bind_param("i", $param))
39		printf("[006] [%d] %s\n", $stmt1->errno, $stmt1->error);
40
41	if (!$stmt2->bind_param("i", $param))
42		printf("[007] [%d] %s\n", $stmt2->errno, $stmt2->error);
43
44	/* first insert normal value to force initial send of types */
45	if (!$stmt1->execute())
46		printf("[008] [%d] %s\n", $stmt1->errno, $stmt1->error);
47
48	if	(!$stmt2->execute())
49		printf("[009] [%d] %s\n", $stmt2->errno, $stmt2->error);
50
51	/* now try values that don't fit in long, on 32bit, new types should be sent or 0 will be inserted */
52	$param = -4294967297;
53	if (!$stmt2->execute())
54		printf("[010] [%d] %s\n", $stmt2->errno, $stmt2->error);
55
56	/* again normal value */
57	$param = 43;
58
59	if (!$stmt1->execute())
60		printf("[011] [%d] %s\n", $stmt1->errno, $stmt1->error);
61
62	if	(!$stmt2->execute())
63		printf("[012] [%d] %s\n", $stmt2->errno, $stmt2->error);
64
65	/* again conversion */
66	$param = -4294967295;
67	if (!$stmt2->execute())
68		printf("[013] [%d] %s\n", $stmt2->errno, $stmt2->error);
69
70	$param = 4294967295;
71	if (!$stmt1->execute())
72		printf("[014] [%d] %s\n", $stmt1->errno, $stmt1->error);
73
74	if	(!$stmt2->execute())
75		printf("[015] [%d] %s\n", $stmt2->errno, $stmt2->error);
76
77	$param = 4294967297;
78	if (!$stmt1->execute())
79		printf("[016] [%d] %s\n", $stmt1->errno, $stmt1->error);
80
81	if	(!$stmt2->execute())
82		printf("[017] [%d] %s\n", $stmt2->errno, $stmt2->error);
83
84	$result = $link->query("SELECT * FROM tsint ORDER BY a ASC");
85	$result2 = $link->query("SELECT * FROM tuint ORDER BY a ASC");
86
87	echo "tsint:\n";
88	while ($row = $result->fetch_assoc()) {
89		var_dump($row);
90	}
91	echo "tuint:\n";
92	while ($row = $result2->fetch_assoc()) {
93		var_dump($row);
94	}
95
96	echo "done";
97?>
98--CLEAN--
99<?php
100require_once('connect.inc');
101
102if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
103	printf("[clean] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
104		$host, $user, $db, $port, $socket);
105}
106
107if (!mysqli_query($link, 'DROP TABLE IF EXISTS tuint')) {
108	printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
109}
110
111if (!mysqli_query($link, 'DROP TABLE IF EXISTS tsint')) {
112	printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
113}
114
115mysqli_close($link);
116?>
117--EXPECTF--
118tsint:
119array(1) {
120  ["a"]=>
121  string(11) "-4294967297"
122}
123array(1) {
124  ["a"]=>
125  string(11) "-4294967295"
126}
127array(1) {
128  ["a"]=>
129  string(2) "42"
130}
131array(1) {
132  ["a"]=>
133  string(2) "43"
134}
135array(1) {
136  ["a"]=>
137  string(10) "4294967295"
138}
139array(1) {
140  ["a"]=>
141  string(10) "4294967297"
142}
143tuint:
144array(1) {
145  ["a"]=>
146  string(2) "42"
147}
148array(1) {
149  ["a"]=>
150  string(2) "43"
151}
152array(1) {
153  ["a"]=>
154  string(10) "4294967295"
155}
156array(1) {
157  ["a"]=>
158  string(10) "4294967297"
159}
160done
161