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