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