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