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