xref: /PHP-8.1/ext/mysqli/tests/002.phpt (revision b5a14e6c)
1--TEST--
2mysqli bind_result 1
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12
13    /*** test mysqli_connect 127.0.0.1 ***/
14    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
15       printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
16
17    if (!mysqli_query($link, "DROP TABLE IF EXISTS test_fetch_null"))
18        printf("[002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
19
20    $rc = mysqli_query($link,"CREATE TABLE test_fetch_null(col1 tinyint, col2 smallint,
21        col3 int, col4 bigint,
22        col5 float, col6 double,
23        col7 date, col8 time,
24        col9 varbinary(10),
25        col10 varchar(50),
26        col11 char(20)) ENGINE=" . $engine);
27
28    if (!$rc)
29        printf("[003] Cannot create table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
30
31    $rc = mysqli_query($link, "INSERT INTO test_fetch_null(col1,col10, col11) VALUES(1,'foo1', 1000),(2,'foo2', 88),(3,'foo3', 389789)");
32    if (!$rc)
33        printf("[004] Cannot insert records, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
34
35    $stmt = mysqli_prepare($link, "SELECT col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11 from test_fetch_null ORDER BY col1");
36    mysqli_stmt_bind_result($stmt, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10, $c11);
37    mysqli_stmt_execute($stmt);
38
39    mysqli_stmt_fetch($stmt);
40
41    $test = array($c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8,$c9,$c10,$c11);
42
43    var_dump($test);
44
45    mysqli_stmt_close($stmt);
46    @mysqli_query($link, "DROP TABLE IF EXISTS test_fetch_null");
47    mysqli_close($link);
48    print "done!";
49?>
50--CLEAN--
51<?php
52require_once("connect.inc");
53if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
54   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
55
56if (!mysqli_query($link, "DROP TABLE IF EXISTS test_fetch_null"))
57    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
58
59mysqli_close($link);
60?>
61--EXPECT--
62array(11) {
63  [0]=>
64  int(1)
65  [1]=>
66  NULL
67  [2]=>
68  NULL
69  [3]=>
70  NULL
71  [4]=>
72  NULL
73  [5]=>
74  NULL
75  [6]=>
76  NULL
77  [7]=>
78  NULL
79  [8]=>
80  NULL
81  [9]=>
82  string(4) "foo1"
83  [10]=>
84  string(4) "1000"
85}
86done!
87