1--TEST--
2mysqli_stmt_sqlstate()
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("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
16
17    try {
18        mysqli_stmt_sqlstate($stmt);
19    } catch (Error $exception) {
20        echo $exception->getMessage() . "\n";
21    }
22
23    if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test"))
24        printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
25
26    if ('00000' !== ($tmp = mysqli_stmt_sqlstate($stmt)))
27        printf("[007] Expecting string/00000, got %s/%s. [%d] %s\n",
28            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
29
30    if (mysqli_stmt_prepare($stmt, "SELECT believe_me FROM i_dont_belive_that_this_table_exists"))
31        printf("[008] Should fail! [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
32
33    if ('' === ($tmp = mysqli_stmt_sqlstate($stmt)))
34        printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
35
36    mysqli_stmt_close($stmt);
37
38    try {
39        mysqli_stmt_sqlstate($stmt);
40    } catch (Error $exception) {
41        echo $exception->getMessage() . "\n";
42    }
43
44    mysqli_close($link);
45    print "done!";
46?>
47--CLEAN--
48<?php
49    require_once("clean_table.inc");
50?>
51--EXPECT--
52mysqli_stmt object is not fully initialized
53mysqli_stmt object is already closed
54done!
55