1--TEST--
2Interface of the class mysqli_stmt
3--SKIPIF--
4<?php
5	require_once('skipif.inc');
6	require_once('skipifemb.inc');
7	require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require('connect.inc');
12	require('table.inc');
13
14	$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
15	$stmt = new mysqli_stmt($link);
16
17	printf("Parent class:\n");
18	var_dump(get_parent_class($stmt));
19
20	printf("\nMethods:\n");
21
22	$methods = get_class_methods($stmt);
23	$expected_methods = array(
24		'__construct'       => true,
25		'attr_get'          => true,
26		'attr_set'          => true,
27		'bind_param'        => true,
28		'bind_result'       => true,
29		'close'             => true,
30		'data_seek'         => true,
31		'execute'           => true,
32		'fetch'             => true,
33		'free_result'       => true,
34		'get_warnings'      => true,
35		'num_rows'          => true,
36		'prepare'           => true,
37		'reset'             => true,
38		'result_metadata'   => true,
39		'send_long_data'    => true,
40		'store_result'      => true,
41	);
42
43	if ($IS_MYSQLND) {
44		$expected_methods['get_result'] = true;
45		$expected_methods['more_results'] = true;
46		$expected_methods['next_result'] = true;
47	}
48
49	foreach ($methods as $k => $method) {
50	if (isset($expected_methods[$method])) {
51		unset($methods[$k]);
52		unset($expected_methods[$method]);
53	}
54		if ($method == 'mysqli_stmt') {
55			// get_class_method reports different constructor names
56			unset($expected_methods['__construct']);
57			unset($methods[$k]);
58		}
59	}
60	if (!empty($methods)) {
61		printf("More methods found than indicated. Dumping list of unexpected methods.\n");
62		var_dump($methods);
63	}
64	if (!empty($expected_methods)) {
65		printf("Some methods are missing. Dumping list of missing methods.\n");
66		var_dump($expected_methods);
67	}
68	if (empty($methods) && empty($expected_methods))
69		printf("ok\n");
70
71	printf("\nClass variables:\n");
72	$variables = array_keys(get_class_vars(get_class($stmt)));
73	sort($variables);
74	foreach ($variables as $k => $var)
75		printf("%s\n", $var);
76
77	printf("\nObject variables:\n");
78	$variables = array_keys(get_object_vars($stmt));
79	foreach ($variables as $k => $var)
80		printf("%s\n", $var);
81
82printf("\nMagic, magic properties:\n");
83
84assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
85printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
86
87if (!$stmt->prepare("INSERT INTO test(id, label) VALUES (100, 'z')") ||
88!$stmt->execute())
89printf("[001] [%d] %s\n", $stmt->errno, $stmt->error);
90
91assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
92printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
93
94assert(mysqli_stmt_errno($stmt) === $stmt->errno);
95printf("stmt->errno = '%s'\n", $stmt->errno);
96
97assert(mysqli_stmt_error($stmt) === $stmt->error);
98printf("stmt->error = '%s'\n", $stmt->error);
99
100assert(mysqli_stmt_error_list($stmt) === $stmt->error_list);
101var_dump("stmt->error = ", $stmt->error_list);
102
103assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
104printf("stmt->field_count = '%s'\n", $stmt->field_count);
105
106assert($stmt->id > 0);
107printf("stmt->id = '%s'\n", $stmt->id);
108
109assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
110printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
111
112assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
113printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
114
115assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
116printf("stmt->param_count = '%s'\n", $stmt->param_count);
117
118assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
119printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
120
121printf("\nAccess to undefined properties:\n");
122printf("stmt->unknown = '%s'\n", @$stmt->unknown);
123@$stmt->unknown = 13;
124printf("stmt->unknown = '%s'\n", @$stmt->unknown);
125
126printf("\nPrepare using the constructor:\n");
127$stmt = new mysqli_stmt($link, 'SELECT id FROM test ORDER BY id');
128if (!$stmt->execute())
129printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
130$stmt->close();
131
132$obj = new stdClass();
133if (!is_object($stmt = new mysqli_stmt($link, $obj)))
134printf("[003] Expecting NULL got %s/%s\n", gettype($stmt), $stmt);
135
136print "done!";
137?>
138--EXPECTF--
139Parent class:
140bool(false)
141
142Methods:
143ok
144
145Class variables:
146affected_rows
147errno
148error
149error_list
150field_count
151id
152insert_id
153num_rows
154param_count
155sqlstate
156
157Object variables:
158affected_rows
159insert_id
160num_rows
161param_count
162field_count
163errno
164error
165error_list
166sqlstate
167id
168
169Magic, magic properties:
170
171Warning: mysqli_stmt_affected_rows(): invalid object or resource mysqli_stmt
172 in %s on line %d
173
174Warning: main(): Property access is not allowed yet in %s on line %d
175
176Warning: main(): Property access is not allowed yet in %s on line %d
177stmt->affected_rows = ''
178stmt->affected_rows = '1'
179stmt->errno = '0'
180stmt->error = ''
181string(14) "stmt->error = "
182array(0) {
183}
184stmt->field_count = '0'
185stmt->id = '%d'
186stmt->insert_id = '0'
187stmt->num_rows = '0'
188stmt->param_count = '0'
189stmt->sqlstate = '00000'
190
191Access to undefined properties:
192stmt->unknown = ''
193stmt->unknown = '13'
194
195Prepare using the constructor:
196
197Warning: mysqli_stmt::__construct() expects parameter 2 to be string, object given in %s on line %d
198done!
199