mysqli_commit> <mysqli_client_encoding
Last updated: Mon, 28 Dec 2009

mysqli_close

mysqli->close

(PHP 5)

mysqli->close — Fecha uma conexão aberta anteriormente com o banco de dados

Descrição

Estilo de procedimento:

bool mysqli_close ( object $link )

Estilo orientado a objeto (metodo):

mysqli
bool close ( void )

A função mysqli_close() fecha uma conexão com um banco de dados aberto anteriormente especificado pelo parâmetro link .

Valores de retorno

Retorna TRUE em caso de sucesso ou FALSE em falhas.



mysqli_commit> <mysqli_client_encoding
Last updated: Mon, 28 Dec 2009
 
User Contributed Notes
mysqli_close
shladnik
05-Jan-2008 10:24
I agree that resources should be freed as soon as posibble. What i was trying to point out at first is that there is no sense to call mysqli->close right before destroying mysqli object as connection will be closed anyway.

If you don't need the connection anymore then i think it is better to destroy whole mysqli object by unsetting its variable and also connection will be closed consequentially. Probably some more resources will be freed this way.

That is why i think that mysqli->close is usefull only when the same object is meant to be reused later.
shladnik
12-Dec-2007 05:08
(i am Anonymous from 09-Dec-2007)

When object is destroyed everything about it is destroyed including conection, without calling close. Or this assumption is wrong?

I think if connection is not closed at the end of a script this is actually misbehave of a php engine or mysqli module. But if we don't trust them, we aslo can't trust close method.
peter
12-Dec-2007 10:25
With regards to the post by the anonymous user related to not needing to use the close method.

Although connections do usually close automatically at the end of a scripts running process. It is better practice to close any resources (including database connections) that you open to ensure that they do indeed close.
Anonymous
09-Dec-2007 01:08
I saw examples when objects extending mysqli object calls parent::close in it's destructor. I beleive this is not needed. Connection is closed anyway when object is destroyed.
I think this function is meant to be called when you want to establish different connection within the same object or when the script goes idle for some time.

mysqli_commit> <mysqli_client_encoding
Last updated: Mon, 28 Dec 2009