xref: /PHP-8.3/ext/mysqli/tests/010.phpt (revision a21edc52)
1--TEST--
2mysqli fetch float values
3--INI--
4precision=12
5--EXTENSIONS--
6mysqli
7--SKIPIF--
8<?php
9require_once 'skipifconnectfailure.inc';
10?>
11--FILE--
12<?php
13    require_once 'connect.inc';
14
15    /*** test mysqli_connect 127.0.0.1 ***/
16    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
17
18    if (!mysqli_query($link, "SET sql_mode=''"))
19        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
20
21    if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch"))
22        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
23
24    $rc = mysqli_query($link, "CREATE TABLE test_bind_fetch(c1 float(3),
25                                                     c2 float,
26                                                     c3 float unsigned,
27                                                     c4 float,
28                                                     c5 float,
29                                                     c6 float,
30                                                     c7 float(10) unsigned) ENGINE=" . $engine);
31    if (!$rc)
32        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
33
34
35    mysqli_query($link, "INSERT INTO test_bind_fetch (c1,c2,c3,c4,c5,c6,c7) VALUES (3.1415926535,-0.000001, -5, 999999999999,
36                                            sin(0.6), 1.00000000000001, 888888888888888)");
37
38    $stmt = mysqli_prepare($link, "SELECT * FROM test_bind_fetch");
39    mysqli_stmt_bind_result($stmt, $c1, $c2, $c3, $c4, $c5, $c6, $c7);
40    mysqli_stmt_execute($stmt);
41    mysqli_stmt_fetch($stmt);
42
43    $test = array($c1,$c2,$c3,$c4,$c5,$c6,$c7);
44
45    var_dump($test);
46
47    mysqli_stmt_close($stmt);
48    mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch");
49    mysqli_close($link);
50    print "done!";
51?>
52--CLEAN--
53<?php
54require_once 'connect.inc';
55if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
56   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
57
58if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch"))
59    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
60
61mysqli_close($link);
62?>
63--EXPECT--
64array(7) {
65  [0]=>
66  float(3.14159)
67  [1]=>
68  float(-1.0E-6)
69  [2]=>
70  float(0)
71  [3]=>
72  float(1000000000000)
73  [4]=>
74  float(0.564642)
75  [5]=>
76  float(1)
77  [6]=>
78  float(888889000000000)
79}
80done!
81