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