PHP Doku:: Closes a previously opened database connection - mysqli.close.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAnbieterspezifische DatenbankerweiterungenMySQL Improved ExtensionThe MySQLi classmysqli::close -- mysqli_close

Ein Service von Reinhard Neidl - Webprogrammierung.

The MySQLi class

<<mysqli->client_version -- mysqli_get_client_version

mysqli::commit -- mysqli_commit>>

mysqli::close

mysqli_close

(PHP 5)

mysqli::close -- mysqli_closeCloses a previously opened database connection

Beschreibung

Objektorientierter Stil

bool mysqli::close ( void )

Prozeduraler Stil

bool mysqli_close ( mysqli $link )

Closes a previously opened database connection.

Parameter-Liste

link

Nur bei prozeduralem Aufruf: Ein von mysqli_connect() oder mysqli_init() zurückgegebenes Verbindungsobjekt.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiele

See mysqli_connect().

Siehe auch


3 BenutzerBeiträge:
- Beiträge aktualisieren...
Anonymous
23.04.2010 23:43
The mysqli_close() function and object method only remove the ability to use the mysql object again in the script, essentially on the surface only nulling out all object parameters.

At least with PHP5.3.2 and Windows connecting by tcp, this differs by the old mysql_close() function in that it does not actually close out the tcp socket being used.  You should always use mysqli_kill() function before mysqli_close() to actually close and free up the tcp socket being used by PHP.  Garbage collection after script execution nor mysqli_close() do not kill the tcp socket on their own.  The socket would otherwise remain in 'wait' state for approximately 30 seconds, and any additional page loads/connection attempts would only add to the total number of open tcp connections.  This wait time does not appear to be configurable via PHP settings.

Also as of this version, mysqli created links cannot be "deactivated", and will continue to accumulate in process memory until the PHP server or process is restarted, essentially making mysqli.max_links = -1 required.
php at dafydd dot com
7.11.2008 22:03
I've had situations where database connections appeared to persist following php execution. So, now, my __destructor function explicitly contains a $cxn->close(). It hurts nothing, and helps avoid memory leaks.
win at alinto dot com
21.05.2008 11:52
There's nothing here about connexions automatically claused at the end of a script. About that, a little note from devzone.zend.com :

"Open connections (and similar resources) are automatically destroyed at the end of script execution. However, you should still close or free all connections, result sets and statement handles as soon as they are no longer required. This will help return resources to PHP and MySQL faster."



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)