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    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
84try {
85    mysqli_stmt_affected_rows($stmt);
86} catch (Error $exception) {
87    echo $exception->getMessage() . "\n";
88}
89
90try {
91    $stmt->affected_rows;
92} catch (Error $exception) {
93    echo $exception->getMessage() . "\n";
94}
95
96if (!$stmt->prepare("INSERT INTO test(id, label) VALUES (100, 'z')") || !$stmt->execute()) {
97    printf("[001] [%d] %s\n", $stmt->errno, $stmt->error);
98}
99
100assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
101printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
102
103assert(mysqli_stmt_errno($stmt) === $stmt->errno);
104printf("stmt->errno = '%s'\n", $stmt->errno);
105
106assert(mysqli_stmt_error($stmt) === $stmt->error);
107printf("stmt->error = '%s'\n", $stmt->error);
108
109assert(mysqli_stmt_error_list($stmt) === $stmt->error_list);
110var_dump("stmt->error = ", $stmt->error_list);
111
112assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
113printf("stmt->field_count = '%s'\n", $stmt->field_count);
114
115assert($stmt->id > 0);
116printf("stmt->id = '%s'\n", $stmt->id);
117
118assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
119printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
120
121assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
122printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
123
124assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
125printf("stmt->param_count = '%s'\n", $stmt->param_count);
126
127assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
128printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
129
130printf("\nAccess to undefined properties:\n");
131printf("stmt->unknown = '%s'\n", @$stmt->unknown);
132@$stmt->unknown = 13;
133printf("stmt->unknown = '%s'\n", @$stmt->unknown);
134
135print "done!";
136?>
137--EXPECTF--
138Parent class:
139bool(false)
140
141Methods:
142ok
143
144Class variables:
145affected_rows
146errno
147error
148error_list
149field_count
150id
151insert_id
152num_rows
153param_count
154sqlstate
155
156Object variables:
157
158Magic, magic properties:
159mysqli_stmt object is not fully initialized
160Property access is not allowed yet
161stmt->affected_rows = '1'
162stmt->errno = '0'
163stmt->error = ''
164string(14) "stmt->error = "
165array(0) {
166}
167stmt->field_count = '0'
168stmt->id = '%d'
169stmt->insert_id = '0'
170stmt->num_rows = '0'
171stmt->param_count = '0'
172stmt->sqlstate = '00000'
173
174Access to undefined properties:
175stmt->unknown = ''
176stmt->unknown = '13'
177done!
178