xref: /PHP-7.4/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('skipifemb.inc');
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);
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);
22    @$mysql_2->close();
23
24    /* Re-use persistent connection */
25    $mysql_3 = new mysqli('p:'.$host, $user, $passwd, $db);
26    $error = mysqli_connect_errno();
27    $result = $mysql_3->query("SHOW STATUS LIKE 'Connections'");
28    $c3 = $result->fetch_row();
29    $result->free();
30    $mysql_3->close();
31
32    if (end($c1) !== end($c3))
33        printf("[001] Expected '%d' got '%d'.\n", end($c1), end($c3));
34
35    if ($error !== 0)
36        printf("[002] Expected '0' got '%d'.\n", $error);
37
38    print "done!";
39?>
40--EXPECT--
41done!
42