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