Check closed connection

Asked

Viewed 207 times

4

How can I check if a connection has actually been closed?

    $con = new Conexao();
    $con->abrirConexao();
    ...
    $con->fecharConexao();

I use a variable to instantiate the class Conexao which is in another file. I would just like to know how I can verify if the method fecharConexão() actually closed the previously opened connection.

My method for closing the connection is this:

public function fecharConexao(){
    return mysqli_close($this->conexao);          
}

I would just like a notification (just so I know) that the connection has ended. How do I do this?

1 answer

3


The function mysqli_close() returns boolean value

true: indicates that you have successfully executed

false: indicates that there has been an error.

Basically, just check the return value.

Return true, the connection was closed.

  • only by completing, if you want to be able to retrieve it at any time, save the return in a class attribute. Example: Connection started $this->aberta = true the connection ended $this->aberta = false this will make it possible to create a method such as public function estaAberta() and this function returns the value of $this->aberta.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.