xref: /PHP-8.3/ext/mysqli/tests/009.phpt (revision a21edc52)
1--TEST--
2mysqli fetch bigint values (ok to fail with 4.1.x)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7    if (PHP_INT_SIZE == 8) {
8        echo 'skip test valid only for 32bit systems';
9        exit;
10    }
11    require_once 'skipifconnectfailure.inc';
12?>
13--FILE--
14<?php
15    require_once 'connect.inc';
16
17    /*** test mysqli_connect 127.0.0.1 ***/
18    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
19
20    if (!mysqli_query($link, "SET sql_mode=''"))
21        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22
23    if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch"))
24        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
25
26    $rc = mysqli_query($link,"CREATE TABLE test_bind_fetch(c1 bigint default 5,
27                                                    c2 bigint,
28                                                    c3 bigint not NULL,
29                                                    c4 bigint unsigned,
30                                                    c5 bigint unsigned,
31                                                    c6 bigint unsigned,
32                                                    c7 bigint unsigned,
33                                                    c8 bigint unsigned) ENGINE=" . $engine);
34    if (!$rc)
35        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
36
37    $rc = mysqli_query($link, "INSERT INTO test_bind_fetch (c2,c3,c4,c5,c6,c7,c8) ".
38                              "VALUES (-23,4.0,33333333333333,0,-333333333333,99.9,1234)");
39    if (!$rc)
40        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
41
42    $stmt = mysqli_prepare($link, "SELECT * FROM test_bind_fetch");
43    mysqli_stmt_bind_result($stmt, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8);
44    mysqli_stmt_execute($stmt);
45    $rc = mysqli_stmt_fetch($stmt);
46
47    if (mysqli_get_server_version($link) < 50000) {
48        // 4.1 is faulty and will return big number for $c6
49        if ($c6 == "18446743740376218283") {
50            $c6 = 0;
51        }
52    }
53    $c8 = 4567;// change this to test how mysqli/mysqlnd handles is_ref changing
54    $test = array($c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8);
55
56    var_dump($test);
57
58    mysqli_stmt_close($stmt);
59
60    if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch_uint"))
61        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
62    $rc = mysqli_query($link, "CREATE TABLE test_bind_fetch_uint(c1 integer unsigned, c2 integer unsigned) ENGINE=" . $engine);
63    if (!$rc)
64        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
65
66    if (!mysqli_query($link, "INSERT INTO test_bind_fetch_uint (c1,c2) VALUES (20123456, 3123456789)"))
67        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
68
69    $stmt = mysqli_prepare($link, "SELECT * FROM test_bind_fetch_uint");
70    mysqli_stmt_bind_result($stmt, $c1, $c2);
71    mysqli_stmt_execute($stmt);
72    $rc = mysqli_stmt_fetch($stmt);
73
74    echo $c1, "\n", $c2, "\n";
75
76    mysqli_stmt_close($stmt);
77    mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch");
78    mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch_uint");
79    mysqli_close($link);
80    print "done!";
81?>
82--CLEAN--
83<?php
84require_once 'connect.inc';
85if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
86   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
87
88if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch"))
89    printf("[002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
90
91if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch_uint"))
92    printf("[002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
93
94mysqli_close($link);
95?>
96--EXPECT--
97array(8) {
98  [0]=>
99  int(5)
100  [1]=>
101  int(-23)
102  [2]=>
103  int(4)
104  [3]=>
105  string(14) "33333333333333"
106  [4]=>
107  int(0)
108  [5]=>
109  int(0)
110  [6]=>
111  int(100)
112  [7]=>
113  int(4567)
114}
11520123456
1163123456789
117done!
118