1--TEST--
2Interface of the class mysqli_stmt
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
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    $expected_methods['get_result'] = true;
44    $expected_methods['more_results'] = true;
45    $expected_methods['next_result'] = true;
46
47    foreach ($methods as $k => $method) {
48    if (isset($expected_methods[$method])) {
49        unset($methods[$k]);
50        unset($expected_methods[$method]);
51    }
52        if ($method == 'mysqli_stmt') {
53            // get_class_method reports different constructor names
54            unset($expected_methods['__construct']);
55            unset($methods[$k]);
56        }
57    }
58    if (!empty($methods)) {
59        printf("More methods found than indicated. Dumping list of unexpected methods.\n");
60        var_dump($methods);
61    }
62    if (!empty($expected_methods)) {
63        printf("Some methods are missing. Dumping list of missing methods.\n");
64        var_dump($expected_methods);
65    }
66    if (empty($methods) && empty($expected_methods))
67        printf("ok\n");
68
69    printf("\nClass variables:\n");
70    $variables = array_keys(get_class_vars(get_class($stmt)));
71    sort($variables);
72    foreach ($variables as $k => $var)
73        printf("%s\n", $var);
74
75    printf("\nObject variables:\n");
76    $variables = array_keys(get_object_vars($stmt));
77    foreach ($variables as $k => $var)
78        printf("%s\n", $var);
79
80printf("\nMagic, magic properties:\n");
81
82try {
83    mysqli_stmt_affected_rows($stmt);
84} catch (Error $exception) {
85    echo $exception->getMessage() . "\n";
86}
87
88try {
89    $stmt->affected_rows;
90} catch (Error $exception) {
91    echo $exception->getMessage() . "\n";
92}
93
94if (!$stmt->prepare("INSERT INTO test(id, label) VALUES (100, 'z')") || !$stmt->execute()) {
95    printf("[001] [%d] %s\n", $stmt->errno, $stmt->error);
96}
97
98assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
99printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
100
101assert(mysqli_stmt_errno($stmt) === $stmt->errno);
102printf("stmt->errno = '%s'\n", $stmt->errno);
103
104assert(mysqli_stmt_error($stmt) === $stmt->error);
105printf("stmt->error = '%s'\n", $stmt->error);
106
107assert(mysqli_stmt_error_list($stmt) === $stmt->error_list);
108var_dump("stmt->error = ", $stmt->error_list);
109
110assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
111printf("stmt->field_count = '%s'\n", $stmt->field_count);
112
113assert($stmt->id > 0);
114printf("stmt->id = '%s'\n", $stmt->id);
115
116assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
117printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
118
119assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
120printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
121
122assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
123printf("stmt->param_count = '%s'\n", $stmt->param_count);
124
125assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
126printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
127
128printf("\nAccess to undefined properties:\n");
129printf("stmt->unknown = '%s'\n", @$stmt->unknown);
130@$stmt->unknown = 13;
131printf("stmt->unknown = '%s'\n", @$stmt->unknown);
132
133print "done!";
134?>
135--EXPECTF--
136Parent class:
137bool(false)
138
139Methods:
140ok
141
142Class variables:
143affected_rows
144errno
145error
146error_list
147field_count
148id
149insert_id
150num_rows
151param_count
152sqlstate
153
154Object variables:
155
156Magic, magic properties:
157mysqli_stmt object is not fully initialized
158Property access is not allowed yet
159stmt->affected_rows = '1'
160stmt->errno = '0'
161stmt->error = ''
162string(14) "stmt->error = "
163array(0) {
164}
165stmt->field_count = '0'
166stmt->id = '%d'
167stmt->insert_id = '0'
168stmt->num_rows = '0'
169stmt->param_count = '0'
170stmt->sqlstate = '00000'
171
172Access to undefined properties:
173stmt->unknown = ''
174stmt->unknown = '13'
175done!
176