xref: /PHP-8.3/ext/mysqli/tests/mysqli_error.phpt (revision a21edc52)
1--TEST--
2mysqli_error()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    require_once 'connect.inc';
12
13    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
14        printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
15            $host, $user, $db, $port, $socket);
16    }
17
18    $tmp = mysqli_error($link);
19    if (!is_string($tmp) || ('' !== $tmp))
20        printf("[004] Expecting string/empty, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
21
22    if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) {
23        printf("[005] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
24    }
25
26    mysqli_query($link, 'SELECT * FROM test');
27    $tmp = mysqli_error($link);
28    if (!is_string($tmp) || !preg_match("/Table '\w*\.test' doesn't exist/su", $tmp))
29        printf("[006] Expecting string/[Table... doesn't exit], got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
30
31    mysqli_close($link);
32
33    try {
34        mysqli_error($link);
35    } catch (Error $exception) {
36        echo $exception->getMessage() . "\n";
37    }
38
39    print "done!";
40?>
41--EXPECT--
42mysqli object is already closed
43done!
44