1--TEST--
2mysqli_stmt_sqlstate()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12
13    $tmp    = NULL;
14    $link   = NULL;
15
16    if (!is_null($tmp = @mysqli_stmt_sqlstate()))
17        printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18
19    if (!is_null($tmp = @mysqli_stmt_sqlstate($link)))
20        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21
22    require('table.inc');
23
24    if (!is_null($tmp = @mysqli_stmt_sqlstate($link, '')))
25        printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
26
27    if (!$stmt = mysqli_stmt_init($link))
28        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
29
30    if (false !== ($tmp = mysqli_stmt_sqlstate($stmt)))
31        printf("[005] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
32
33    if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test"))
34        printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
35
36    if ('00000' !== ($tmp = mysqli_stmt_sqlstate($stmt)))
37        printf("[007] Expecting string/00000, got %s/%s. [%d] %s\n",
38            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
39
40    if (mysqli_stmt_prepare($stmt, "SELECT believe_me FROM i_dont_belive_that_this_table_exists"))
41        printf("[008] Should fail! [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
42
43    if ('' === ($tmp = mysqli_stmt_sqlstate($stmt)))
44        printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
45
46    mysqli_stmt_close($stmt);
47
48    if (false !== ($tmp = mysqli_stmt_sqlstate($stmt)))
49        printf("[010] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
50
51    mysqli_close($link);
52    print "done!";
53?>
54--CLEAN--
55<?php
56    require_once("clean_table.inc");
57?>
58--EXPECTF--
59Warning: mysqli_stmt_sqlstate(): invalid object or resource mysqli_stmt
60 in %s on line %d
61
62Warning: mysqli_stmt_sqlstate(): Couldn't fetch mysqli_stmt in %s on line %d
63done!
64