1--TEST--
2mysqli_stmt_execute()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
8    die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error()));
9}
10if (mysqli_get_server_version($link) <= 40100) {
11    die(sprintf('skip Needs MySQL 4.1+, found version %d.', mysqli_get_server_version($link)));
12}
13?>
14--FILE--
15<?php
16    require_once("connect.inc");
17
18    require('table.inc');
19
20    if (!$stmt = mysqli_stmt_init($link))
21        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22
23    // stmt object status test
24    try {
25        mysqli_stmt_execute($stmt);
26    } catch (Error $exception) {
27        echo $exception->getMessage() . "\n";
28    }
29
30    if (mysqli_stmt_prepare($stmt, "SELECT i_do_not_exist_believe_me FROM test ORDER BY id"))
31        printf("[005] Statement should have failed!\n");
32
33    // stmt object status test
34    try {
35        mysqli_stmt_execute($stmt);
36    } catch (Error $exception) {
37        echo $exception->getMessage() . "\n";
38    }
39
40    if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT 1"))
41        printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
42
43    if (true !== ($tmp = mysqli_stmt_execute($stmt)))
44        printf("[008] Expecting boolean/true, got %s/%s. [%d] %s\n",
45            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
46
47    if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)"))
48        printf("[009] [%d] %s\n", mysqli_stmt_execute($stmt), mysqli_stmt_execute($stmt));
49
50    // no input variables bound
51    if (false !== ($tmp = mysqli_stmt_execute($stmt)))
52        printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
53
54    $id = 100;
55    $label = "z";
56    if (!mysqli_stmt_bind_param($stmt, "is", $id, $label))
57        printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
58
59    if (true !== ($tmp = mysqli_stmt_execute($stmt)))
60        printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
61
62    // calling reset between executions
63    mysqli_stmt_close($stmt);
64    if (!$stmt = mysqli_stmt_init($link))
65        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
66
67    if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT ?"))
68        printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
69
70    $limit = 1;
71    if (!mysqli_stmt_bind_param($stmt, "i", $limit))
72        printf("[015] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
73
74    if (true !== ($tmp = mysqli_stmt_execute($stmt)))
75        printf("[016] Expecting boolean/true, got %s/%s. [%d] %s\n",
76            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
77
78    $id = null;
79    if (!mysqli_stmt_bind_result($stmt, $id) || !mysqli_stmt_fetch($stmt))
80        printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
81
82    if ($id !== 1)
83        printf("[018] Expecting int/1 got %s/%s\n", gettype($id), $id);
84
85    if (true !== ($tmp = mysqli_stmt_reset($stmt)))
86        printf("[019] Expecting boolean/true, got %s/%s. [%d] %s\n",
87            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
88
89    if (true !== ($tmp = mysqli_stmt_execute($stmt)))
90        printf("[020] Expecting boolean/true after reset to prepare status, got %s/%s. [%d] %s\n",
91            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
92
93    $id = null;
94    if (!mysqli_stmt_fetch($stmt))
95        printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
96
97    if ($id !== 1)
98        printf("[022] Expecting int/1 got %s/%s\n", gettype($id), $id);
99
100    mysqli_stmt_close($stmt);
101    if (!$stmt = mysqli_stmt_init($link))
102        printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
103
104    if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT 1"))
105        printf("[024] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
106
107    if (true !== ($tmp = mysqli_stmt_execute($stmt)))
108        printf("[025] Expecting boolean/true, got %s/%s. [%d] %s\n",
109            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
110
111    if (true !== ($tmp = mysqli_stmt_reset($stmt)))
112        printf("[026] Expecting boolean/true, got %s/%s. [%d] %s\n",
113            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
114
115    var_dump(mysqli_stmt_execute($stmt));
116    var_dump(mysqli_stmt_fetch($stmt));
117
118    mysqli_kill($link, mysqli_thread_id($link));
119
120    if (false !== ($tmp = mysqli_stmt_execute($stmt)))
121        printf("[027] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
122
123    mysqli_stmt_close($stmt);
124
125    try {
126        mysqli_stmt_execute($stmt);
127    } catch (Error $exception) {
128        echo $exception->getMessage() . "\n";
129    }
130
131    mysqli_close($link);
132    print "done!";
133?>
134--CLEAN--
135<?php
136    require_once("clean_table.inc");
137?>
138--EXPECT--
139mysqli_stmt object is not fully initialized
140mysqli_stmt object is not fully initialized
141bool(true)
142bool(true)
143[027] Expecting boolean/false, got boolean/1
144mysqli_stmt object is already closed
145done!
146