How to Check Whether mysqli connection is open before closing it

后端 未结 7 1841
野趣味
野趣味 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:09

    This is from PHP.net.

    Object oriented style


    connect_errno) {
        printf("Connect failed: %s\n", $mysqli->connect_error);
        exit();
    }
    
    /* check if server is alive */
    if ($mysqli->ping()) {
        printf ("Our connection is ok!\n");
    } else {
        printf ("Error: %s\n", $mysqli->error);
    }
    
    /* close connection */
    $mysqli->close();
    ?>
    

    Procedural style


    
    

提交回复
热议问题