J'ai réécrit mas fonction genérique de connection au serveur (deux fonctions en fait) j'ai laissé l'ancienne fonction en place pour des raisons de compatibilité :

[code:1:b271da98fc]
&lt;?php

/* Purpose &#58; this a generic mysql connection handling script, it provides server specific connection routines interfacing as well as database selection and connection cleaning */

// written by Olivier Cant
// Created on  January 28 2003
// Last Update Fabruary 21 2004
// Current version &#58; 0.2

/* changelog

version 0.2 &#58; February 21 2004
	update use of mysql_pconnect routine to mysql_connect because pconnect is now deprecated.  it's kept for backward compatibility issues and shold be removed in next release
	properly renamed function, but kept the old ones for backward compatibilty reasons, theay also should be removed in next release
	&#40;finally&#41; implemented f_db_close&#40;&#41; function

*/

/* functions description
	Global variables used &#58;
	$fichierConnect =&gt; include once security
	$dbUser =&gt; User used to connect to MySQL Server
	$dbPass =&gt; Pass of the MySQL user
	$dbBase =&gt; Database to be selected in the Server
	$dbServer =&gt; Address of the MySQL Server
	
	Functions &#58;
	Connect *** Deprecated *** =&gt; Used f_dbConnect instead
	ressource = f_dbConnect&#40;$dbUser string,$dbPass string,$dbBase string,$dbServer string&#41;
		f_dbConnect handle the connection to the server and the database selection, it use 			the $dbUser with the $dbPass to connect to MySQL and it select the $dbBase inside 			that Server.  The sever to wich the function connects to is $dbServer
		If the connection is successful, it returns a ressource identifier pointing to the 			connection. Otherwise it returns false and siplays the MySQL error message if 			available or a generic &quot;impossible to connect&quot; message
	
	bool = f_dbClose&#40;$connection ressource&#41;
		f_dbClose closes the $connection transactionnal connection to the MySQL server it 			returns TRUE if it succeeds, FALSE othewise
		note to 0.1 users &#58; this function doesn't work with the Connect function, 			persistant connection with not be implemented in MySQL 5.x so use f_dbConnect 			instead and close connections with f_dbClose
*/

/* to do list

    prevent MySQL from outputting its own error message in case of errors, and let's this script do the error handling 
*/
    

/*This is were the serious stuff starts*/
	
// Iclude once security check

if &#40;!isset &#40;$fichierConnect&#41;&#41;
&#123;
 $fichierConnect = 1;
 
 function f_dbConnect &#40;$dbUser,$dbPass,$dbBase,$dbServer&#41;
 &#123;
    //connection attempt to MySQL Server
    $connection = mysql_connect&#40;$dbServer,$dbUser,$dbPass&#41;;
    if &#40;!$connection&#41;
    &#123;
	echo &quot;Connection impossible au serveur $dbServer\n&quot;;
	return false;
    &#125;
    // connection successful
    // attempt to select database
    if &#40;!mysql_select_db&#40;$dbBase,$connection&#41;&#41;
    &#123;
	echo &quot;une erreur s'est produite lors de la selection de la base de donnee $dbBase\n&quot;;
	echo &quot;&lt;B&gt; Message d'erreur de MySQL &#58; &lt;/B&gt;&quot; . mysql_error&#40;$connection&#41;;
	return false;
    &#125;
    // database successfuly selected
    return $connection;
&#125;

function f_dbClose &#40;$connection&#41;
&#123;
    return mysql_close&#40;$connection&#41;;
&#125;    
 // Connect &#58; *** deprecated *** use f_dbConnect Instead
 
 function Connect &#40;$dbUser,$dbPass,$dbBase,$dbServer&#41;
 &#123;
  // connection to server $dbServer
  $Connection = mysql_pconnect &#40;$dbServer,$dbUser,$dbPass&#41;;
  
  // Test if connection succeeds
  
  if &#40;!$Connection&#41;
  &#123;
   echo &quot;Connection impossible au serveur $dbServer \n&quot;;
   exit;
  &#125;
  
  // Database Selection
  
  if &#40;!mysql_select_db &#40;$dbBase, $dbConnection&#41;&#41;
  &#123;
   echo &quot;Ipmossible de se connecter a la base $dbBase\n&quot;;
   echo &quot;&lt;B&gt; Message d'erreur du serveur &#58; &lt;/B&gt; &quot; . mysql_error&#40;$dbConnection&#41;;
   exit;
  &#125;
  
  // All checks passed succeffuly, returns the connection handler
  return $Connection;
 &#125;
&#125;
?&gt;
[/code:1:b271da98fc]