How to Check Whether mysqli connection is open before closing it

后端 未结 7 1871
野趣味
野趣味 2021-02-04 00:30

I am going to use mysqli_close($connection) to close the $connection. But Before Closing I need to ensure that the concerned connection is open.

<
7条回答
  •  故里飘歌
    2021-02-04 01:35

    Check connection errors. mysqli_connect() always returns a MySQLi object.

    use this:

    $mysqli_connection = new MySQLi('localhost', 'user', 'pass', 'db');
    if ($mysqli_connection->connect_error) {
       echo "Not connected, error: " . $mysqli_connection->connect_error;
    }
    else
    {
       echo "Connected.";
    }
    

提交回复
热议问题