xref: /PHP-8.3/ext/mysqli/tests/mysqli_ping.phpt (revision af4eabd8)
1--TEST--
2mysqli_ping()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    require_once 'connect.inc';
12    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
13        printf("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        exit(1);
16    }
17
18    var_dump(mysqli_ping($link));
19
20    // provoke an error to check if mysqli_ping resets it
21    $res = mysqli_query($link, 'SELECT * FROM unknown_table');
22    if (!($errno = mysqli_errno($link)))
23        printf("[003] Statement should have caused an error\n");
24
25    var_dump(mysqli_ping($link));
26    if ($errno === mysqli_errno($link))
27        printf("[004] Error codes should have been reset\n");
28
29    mysqli_close($link);
30
31    try {
32        mysqli_ping($link);
33    } catch (Error $exception) {
34        echo $exception->getMessage() . "\n";
35    }
36
37    print "done!";
38?>
39--EXPECT--
40bool(true)
41bool(true)
42mysqli object is already closed
43done!
44