includes/dbal.php
changeset 1369 cfce82063776
parent 1342 2164d18cb10c
child 1375 d66e43ac35b6
equal deleted inserted replaced
1368:b19698a37d58 1369:cfce82063776
   206 		if ( $dbhost && !empty($dbport) && $dbport != 3306 )
   206 		if ( $dbhost && !empty($dbport) && $dbport != 3306 )
   207 			$dbhost = '127.0.0.1';
   207 			$dbhost = '127.0.0.1';
   208 		
   208 		
   209 		$host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
   209 		$host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
   210 		
   210 		
   211 		$this->_conn = @mysql_connect($host_line, $dbuser, $dbpasswd);
   211 		// Try a peristent connection twice
       
   212 		// http://us2.php.net/manual/en/function.mysql-pconnect.php#99380
       
   213 		$this->_conn = @mysql_pconnect($host_line, $dbuser, $dbpasswd);
       
   214 		if ( !@mysql_query("SELECT 1;", $this->_conn) )
       
   215 		{
       
   216 			$this->_conn = @mysql_pconnect($host_line, $dbuser, $dbpasswd);
       
   217 			if ( !@mysql_query("SELECT 1;", $this->_conn) )
       
   218 			{
       
   219 				// if that doesn't work, use a normal connection
       
   220 				$this->_conn = @mysql_connect($host_line, $dbuser, $dbpasswd);
       
   221 				trigger_error(E_USER_WARNING, "Forced to use nonpersistent mysql connection");
       
   222 			}
       
   223 		}
   212 		unset($dbuser);
   224 		unset($dbuser);
   213 		unset($dbpasswd); // Security
   225 		unset($dbpasswd); // Security
   214 		
   226 		
   215 		if ( !$this->_conn && !$manual_credentials )
   227 		if ( !$this->_conn && !$manual_credentials )
   216 		{
   228 		{
   534  	* Close the database connection
   546  	* Close the database connection
   535  	*/
   547  	*/
   536 	
   548 	
   537 	function close()
   549 	function close()
   538 	{
   550 	{
       
   551 		// anything we locked should certainly be unlocked now;
       
   552 		@mysql_query("COMMIT;", $this->_conn);
       
   553 		@mysql_query("UNLOCK TABLES;", $this->_conn);
   539 		@mysql_close($this->_conn);
   554 		@mysql_close($this->_conn);
   540 		unset($this->_conn);
   555 		unset($this->_conn);
   541 	}
   556 	}
   542 	
   557 	
   543 	/**
   558 	/**