xref: /PHP-8.0/ext/mysqli/tests/057.phpt (revision e3e67b72)
1--TEST--
2mysqli_stmt_result_metadata
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("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    mysqli_query($link,"DROP TABLE IF EXISTS test_store_result");
18    mysqli_query($link,"CREATE TABLE test_store_result (a int)");
19
20    mysqli_query($link, "INSERT INTO test_store_result VALUES (1),(2),(3)");
21
22    $stmt = mysqli_prepare($link, "SELECT * FROM test_store_result");
23    mysqli_stmt_execute($stmt);
24
25    /* this should produce an out of sync error */
26    if ($result = mysqli_query($link, "SELECT * FROM test_store_result")) {
27        mysqli_free_result($result);
28        printf ("Query ok\n");
29    }
30    mysqli_stmt_close($stmt);
31
32    /* now we should try mysqli_stmt_reset() */
33    $stmt = mysqli_prepare($link, "SELECT * FROM test_store_result");
34    var_dump(mysqli_stmt_execute($stmt));
35    var_dump(mysqli_stmt_reset($stmt));
36
37    var_dump($stmt = mysqli_prepare($link, "SELECT * FROM test_store_result"));
38    if ($stmt->affected_rows !== 0)
39            printf("[001] Expecting 0, got %d\n", $stmt->affected_rows);
40
41    var_dump(mysqli_stmt_execute($stmt));
42    var_dump($stmt = @mysqli_prepare($link, "SELECT * FROM test_store_result"), mysqli_error($link));
43
44    $stmt = mysqli_prepare($link, "SELECT * FROM test_store_result");
45    mysqli_stmt_execute($stmt);
46    $result1 = mysqli_stmt_result_metadata($stmt);
47    mysqli_stmt_store_result($stmt);
48
49    printf ("Rows: %d\n", mysqli_stmt_affected_rows($stmt));
50
51    /* this should show an error, cause results are not buffered */
52    if ($result = mysqli_query($link, "SELECT * FROM test_store_result")) {
53        $row = mysqli_fetch_row($result);
54        mysqli_free_result($result);
55    }
56
57    var_dump($row);
58
59    mysqli_free_result($result1);
60    mysqli_stmt_close($stmt);
61    mysqli_close($link);
62    echo "done!";
63?>
64--CLEAN--
65<?php
66require_once("connect.inc");
67if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
68   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
69
70if (!mysqli_query($link, "DROP TABLE IF EXISTS test_store_result"))
71    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
72
73mysqli_close($link);
74?>
75--EXPECTF--
76bool(true)
77bool(true)
78object(mysqli_stmt)#%d (%d) {
79  ["affected_rows"]=>
80  int(%i)
81  ["insert_id"]=>
82  int(0)
83  ["num_rows"]=>
84  int(0)
85  ["param_count"]=>
86  int(0)
87  ["field_count"]=>
88  int(1)
89  ["errno"]=>
90  int(0)
91  ["error"]=>
92  string(0) ""
93  ["error_list"]=>
94  array(0) {
95  }
96  ["sqlstate"]=>
97  string(5) "00000"
98  ["id"]=>
99  int(%d)
100}
101bool(true)
102bool(false)
103string(0) ""
104Rows: 3
105array(1) {
106  [0]=>
107  string(1) "1"
108}
109done!
110