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