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