xref: /PHP-7.4/ext/mysqli/tests/bug67839.phpt (revision e3e67b72)
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?>
9--INI--
10precision=5
11--FILE--
12<?php
13    require('connect.inc');
14    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
15        printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
16        die();
17    }
18
19
20    if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
21        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22        die();
23    }
24
25    if (!mysqli_query($link, "CREATE TABLE test(id INT PRIMARY KEY, fp4 FLOAT, fp8 DOUBLE) ENGINE = InnoDB")) {
26        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
27        die();
28    }
29
30    // Insert via string to make sure the real floating number gets to the DB
31    if (!mysqli_query($link, "INSERT INTO test(id, fp4, fp8) VALUES (1, 9.9999, 9.9999)")) {
32        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
33        die();
34    }
35
36    if (!($stmt = mysqli_prepare($link, "SELECT id, fp4, fp8 FROM test"))) {
37        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
38        die();
39    }
40
41    $id = null;
42    $fp4 = null;
43    $fp8 = null;
44
45    if (!mysqli_stmt_bind_result($stmt, $id, $fp4, $fp8)) {
46        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
47        die();
48    }
49
50    if (!mysqli_stmt_execute($stmt)) {
51        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
52        die();
53    }
54
55
56    if (!(mysqli_stmt_fetch($stmt))) {
57        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
58        die();
59    }
60
61    print $id . ": " . $fp4 . ": " . $fp8 . "\n";
62?>
63--CLEAN--
64<?php
65    require_once("clean_table.inc");
66?>
67--EXPECT--
681: 9.9999: 9.9999
69