xref: /PHP-7.4/ext/mysqli/tests/004.phpt (revision e3e67b72)
1--TEST--
2mysqli fetch char/text
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    include ("connect.inc");
11
12    /*** test mysqli_connect 127.0.0.1 ***/
13    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
14
15    mysqli_select_db($link, $db);
16
17    if (!mysqli_query($link,"DROP TABLE IF EXISTS test_bind_fetch"))
18        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
19
20    if (!mysqli_query($link,"CREATE TABLE test_bind_fetch(c1 char(10), c2 text) ENGINE=" . $engine))
21        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22
23    if (!mysqli_query($link, "INSERT INTO test_bind_fetch VALUES ('1234567890', 'this is a test0')"))
24        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
25
26    if (!mysqli_query($link, "INSERT INTO test_bind_fetch VALUES ('1234567891', 'this is a test1')"))
27        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
28
29    if (!mysqli_query($link, "INSERT INTO test_bind_fetch VALUES ('1234567892', 'this is a test2')"))
30        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
31
32    if (!mysqli_query($link, "INSERT INTO test_bind_fetch VALUES ('1234567893', 'this is a test3')"))
33        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
34
35    if (!$stmt = mysqli_prepare($link, "SELECT * FROM test_bind_fetch ORDER BY c1"))
36        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
37
38    $c1 = $c2 = NULL;
39    mysqli_stmt_bind_result($stmt, $c1, $c2);
40    mysqli_stmt_execute($stmt);
41    $i = 4;
42    while ($i--) {
43        mysqli_stmt_fetch($stmt);
44        $test = array($c1, $c2);
45        var_dump($test);
46    }
47
48    mysqli_stmt_close($stmt);
49    mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch");
50    mysqli_close($link);
51    print "done!";
52?>
53--CLEAN--
54<?php
55require_once("connect.inc");
56if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
57   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
58
59if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch"))
60    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
61
62mysqli_close($link);
63?>
64--EXPECT--
65array(2) {
66  [0]=>
67  string(10) "1234567890"
68  [1]=>
69  string(15) "this is a test0"
70}
71array(2) {
72  [0]=>
73  string(10) "1234567891"
74  [1]=>
75  string(15) "this is a test1"
76}
77array(2) {
78  [0]=>
79  string(10) "1234567892"
80  [1]=>
81  string(15) "this is a test2"
82}
83array(2) {
84  [0]=>
85  string(10) "1234567893"
86  [1]=>
87  string(15) "this is a test3"
88}
89done!
90