★ wanayoo — archive 1999 http://fr.php.net/manual/fr/function.mysql-close.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<mysql_client_encodingmysql_connect>
view the version of this page
Last updated: Sun, 20 Apr 2003

mysql_close

(PHP 3, PHP 4 )

mysql_close -- Ferme la connexion MySQL

Description

bool mysql_close ( [resource link_identifier])

mysql_close() ferme la connexion au serveur MySQL associée à l'identifiant link_identifier. Si cet identifiant n'est pas spécifié, cette commande s'applique à la dernière connexion ouverte.

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Note : Notez que cette commande n'est pas nécessaire, car toutes les connexions non persistantes seront automatiquement fermées à la fin du script.

mysql_close() ne ferme pas les connexions persistantes générées par mysql_pconnect().

Exemple 1. Exemple MySQL_close

<?php
  $link = mysql_connect("serveur.mysql.com", "utilisateur", "secret") 
    or die("Impossible de se connecter");

  print("Connexion r&eacute;ussie");
  mysql_close($link);
?>

Voir aussi mysql_connect() et mysql_pconnect().



User Contributed Notes
mysql_close
add a note add a note
msplival at jagor dot srce dot hr
18-Jun-2002 09:14

mysql_close seems to have no effect on linux versions of PHP.

I have a function, sqlExecute, where I pass an SQL query to be executed, and the function returns the recordset (or returns nothing if the query begins with UPDATE or INSERT). That function issues mysql_connect at the begining, and mysql_close at the end. But, later in my code, if I have mysql_insert_id AFTER my sqlExecute, it seems to be working fine. Everything was ok untill I tried same thing on Windows version of php. mysql_insert_id complains about having no resource identifier (wich is logical, beacuse I issued a mysql_close in sqlExecute). Do I make any sense? Is that a linux bug (feature?)

derek at nospam dot mapiq dot com
05-Jul-2002 09:02

By the looks of it Linux version of PHP doesnt close the connection at all. I tested a few different ways of trying to close the connection, but havent found anything thats really useful as of yet.

Below is what I use for my connections:

class database
{
 var $host = "www.somesite.com";
 var $user = "user";
 var $pass = "p4ssw0rd";
 
 var $d_base;
 var $conx;
var $db;

 function connectdb ( $db_name="dbase" )
{
   $this->d_base = $db_name;

   $this->conx = mysql_connect ( $this->host, $this->user, $this->pass ) or sql_error ( "db-connect", mysql_error() );

  $this->db = mysql_select_db ( $this->d_base, $this->conx ) or sql_error ( "db-select", mysql_error() );

 }

function closedb ( )
 {

   mysql_close ( $this->conx ) or sql_error ( "db-close", mysql_error() );

 }

}

Then by running a simple test, I do a query and close the connection after it is completed.

$db = New database();

$db->connectdb ();
 
 $q[0] = "SELECT * FROM sometable WHERE id = '$an_id'";
 $sql[0] = mysql_query ( $q[0] ) or sql_error ( "db-query",
mysql_error() );
$res[0] = mysql_fetch_array ( $sql[0] ) or sql_error ( "db-fetch",
mysql_error() );
 
$db->closedb ();

Doing this gives me an error message of "No Database Selected"

In the closedb() function I also tried doing this, to see if this resolved anything, but alas I could continue querying after these were executed.

$this->conx = NULL;
$this->db = NULL;

and

unset ( $this->conx );
unset ( $this->db );

Im not sure if this is intentional or it is an actual bug in PHP, but I wouldnt mind knowing what is the status with this feature.

add a note add a note

<mysql_client_encodingmysql_connect>
 Last updated: Sun, 20 Apr 2003
show source | credits | stats | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Tue May 20 05:09:32 2003 CEST