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