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