xref: /PHP-7.0/ext/mysqli/tests/bug70384.phpt (revision 003b764a)
1--TEST--
2mysqli_float_handling - ensure 4 byte float is handled correctly
3--SKIPIF--
4<?php
5	require_once('skipif.inc');
6	require_once('skipifemb.inc');
7	require_once('skipifconnectfailure.inc');
8	if (@$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
9		if ($link->server_version < 50709) {
10			die("skip MySQL 5.7.9+ needed. Found [".
11				intval(substr($link->server_version."", -5, 1)).
12				".".
13				intval(substr($link->server_version."", -4, 2)).
14				".".
15				intval(substr($link->server_version."", -2, 2)).
16				"]");
17		}
18	}
19?>
20--FILE--
21<?php
22	require('connect.inc');
23	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
24		printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
25		die();
26	}
27
28	if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
29		printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
30		die();
31	}
32
33	if (!mysqli_query($link, "CREATE TABLE test(jsfield JSON) ENGINE = InnoDB")) {
34		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
35		die();
36	}
37	$jsfield_data = '{"aaa": 123}';
38	// Insert via string to make sure the real floating number gets to the DB
39	if (!mysqli_query($link, "INSERT INTO test VALUES ('".$jsfield_data."')")) {
40		printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
41		die();
42	}
43
44	if (!($res = mysqli_query($link, "SELECT *  FROM test"))) {
45		printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
46		die();
47	}
48	$rows = $res->fetch_all();
49	if (json_encode($rows[0][0]) != json_encode($jsfield_data)) {
50		printf("[006] Data differs");
51		var_dump(json_encode($rows[0][0]) != json_encode($jsfield_data));
52		die();
53	}
54	mysqli_close($link);
55	echo "OK";
56?>
57--CLEAN--
58<?php
59	require_once("clean_table.inc");
60?>
61--EXPECTF--
62OK