xref: /PHP-5.4/ext/mysqli/tests/057.phpt (revision c9e7716c)
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 ($IS_MYSQLND && $stmt->affected_rows !== -1)
39			printf("[001] Expecting -1, 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	var_dump(mysqli_stmt_reset($stmt));
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  [%u|b%"affected_rows"]=>
81  int(%i)
82  [%u|b%"insert_id"]=>
83  int(0)
84  [%u|b%"num_rows"]=>
85  int(0)
86  [%u|b%"param_count"]=>
87  int(0)
88  [%u|b%"field_count"]=>
89  int(1)
90  [%u|b%"errno"]=>
91  int(0)
92  [%u|b%"error"]=>
93  %unicode|string%(0) ""
94  [%u|b%"error_list"]=>
95  array(0) {
96  }
97  [%u|b%"sqlstate"]=>
98  %unicode|string%(5) "00000"
99  [%u|b%"id"]=>
100  int(3)
101}
102bool(true)
103bool(false)
104%unicode|string%(0) ""
105
106Warning: mysqli_stmt_reset() expects parameter 1 to be mysqli_stmt, boolean given in %s on line %d
107NULL
108Rows: 3
109array(1) {
110  [0]=>
111  %unicode|string%(1) "1"
112}
113done!