1--TEST--
2mysqli_stmt_error()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12
13    require('table.inc');
14
15    if (!$stmt = mysqli_stmt_init($link))
16        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
17
18    // properly initialized?
19    if ('' !== ($tmp = mysqli_stmt_error($stmt)))
20        printf("[004] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
21
22    if (mysqli_stmt_prepare($stmt, "SELECT i_do_not_exist_believe_me FROM test ORDER BY id"))
23        printf("[005] Statement should have failed!\n");
24
25    // set after error server?
26    if ('' === ($tmp = mysqli_stmt_error($stmt)))
27        printf("[006] Expecting string/any non empty, got %s/%s\n", gettype($tmp), $tmp);
28
29    if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id"))
30        printf("[007] [%d] %s\n", mysqli_stmt_error($stmt), mysqli_stmt_error($stmt));
31
32    // reset after error & success
33    if ('' !== ($tmp = mysqli_stmt_error($stmt)))
34        printf("[008] Expecting empty string, got %s/%s\n", gettype($tmp), $tmp);
35
36    mysqli_kill($link, mysqli_thread_id($link));
37
38    if (true === ($tmp = mysqli_stmt_execute($stmt)))
39        printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
40
41    // set after client error
42    if ('' === ($tmp = mysqli_stmt_error($stmt)))
43        printf("[010] Expecting string/any non empty, got %s/%s\n", gettype($tmp), $tmp);
44
45    mysqli_stmt_close($stmt);
46
47    try {
48        mysqli_stmt_error($stmt);
49    } catch (Error $exception) {
50        echo $exception->getMessage() . "\n";
51    }
52
53    mysqli_close($link);
54    print "done!";
55?>
56--CLEAN--
57<?php
58    require_once("clean_table.inc");
59?>
60--EXPECT--
61mysqli_stmt object is already closed
62done!
63