xref: /PHP-8.0/ext/mysqli/tests/bug73462.phpt (revision e3e67b72)
1--TEST--
2Bug #73462 (Persistent connections don't set $connect_errno)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    /* Initial persistent connection */
13    $mysql_1 = new mysqli('p:'.$host, $user, $passwd, $db);
14    $result = $mysql_1->query("SHOW STATUS LIKE 'Connections'");
15    $c1 = $result->fetch_row();
16    $result->free();
17    $mysql_1->close();
18
19    /* Failed connection to invalid host */
20    $mysql_2 = @new mysqli(' !!! invalid !!! ', $user, $passwd, $db);
21    try {
22        $mysql_2->close();
23    } catch (Error $exception) {
24        echo $exception->getMessage() . "\n";
25    }
26
27    /* Re-use persistent connection */
28    $mysql_3 = new mysqli('p:'.$host, $user, $passwd, $db);
29    $error = mysqli_connect_errno();
30    $result = $mysql_3->query("SHOW STATUS LIKE 'Connections'");
31    $c3 = $result->fetch_row();
32    $result->free();
33    $mysql_3->close();
34
35    if (end($c1) !== end($c3))
36        printf("[001] Expected '%d' got '%d'.\n", end($c1), end($c3));
37
38    if ($error !== 0)
39        printf("[002] Expected '0' got '%d'.\n", $error);
40
41    print "done!";
42?>
43--EXPECT--
44mysqli object is already closed
45done!
46