diff options
Diffstat (limited to 'phpBB/includes/db')
| -rw-r--r-- | phpBB/includes/db/mssql.php | 66 | ||||
| -rw-r--r-- | phpBB/includes/db/mssql_odbc.php | 40 | ||||
| -rw-r--r-- | phpBB/includes/db/mssqlnative.php | 52 | ||||
| -rw-r--r-- | phpBB/includes/db/mysql.php | 45 | ||||
| -rw-r--r-- | phpBB/includes/db/mysqli.php | 32 | ||||
| -rw-r--r-- | phpBB/includes/db/oracle.php | 53 | ||||
| -rw-r--r-- | phpBB/includes/db/sqlite.php | 41 | 
7 files changed, 253 insertions, 76 deletions
diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index b7178593dc..2dd95c2508 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -25,11 +25,19 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);  */  class dbal_mssql extends dbal  { +	var $connect_error = ''; +  	/**  	* Connect to server  	*/  	function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)  	{ +		if (!function_exists('mssql_connect')) +		{ +			$this->connect_error = 'mssql_connect function does not exist, is mssql extension installed?'; +			return $this->sql_error(''); +		} +  		$this->persistency = $persistency;  		$this->user = $sqluser;  		$this->dbname = $database; @@ -355,34 +363,44 @@ class dbal_mssql extends dbal  	*/  	function _sql_error()  	{ -		$error = array( -			'message'	=> @mssql_get_last_message(), -			'code'		=> '' -		); - -		// Get error code number -		$result_id = @mssql_query('SELECT @@ERROR as code', $this->db_connect_id); -		if ($result_id) +		if (function_exists('mssql_get_last_message'))  		{ -			$row = @mssql_fetch_assoc($result_id); -			$error['code'] = $row['code']; -			@mssql_free_result($result_id); -		} +			$error = array( +				'message'	=> @mssql_get_last_message(), +				'code'		=> '', +			); -		// Get full error message if possible -		$sql = 'SELECT CAST(description as varchar(255)) as message -			FROM master.dbo.sysmessages -			WHERE error = ' . $error['code']; -		$result_id = @mssql_query($sql); -		 -		if ($result_id) -		{ -			$row = @mssql_fetch_assoc($result_id); -			if (!empty($row['message'])) +			// Get error code number +			$result_id = @mssql_query('SELECT @@ERROR as code', $this->db_connect_id); +			if ($result_id) +			{ +				$row = @mssql_fetch_assoc($result_id); +				$error['code'] = $row['code']; +				@mssql_free_result($result_id); +			} + +			// Get full error message if possible +			$sql = 'SELECT CAST(description as varchar(255)) as message +				FROM master.dbo.sysmessages +				WHERE error = ' . $error['code']; +			$result_id = @mssql_query($sql); + +			if ($result_id)  			{ -				$error['message'] .= '<br />' . $row['message']; +				$row = @mssql_fetch_assoc($result_id); +				if (!empty($row['message'])) +				{ +					$error['message'] .= '<br />' . $row['message']; +				} +				@mssql_free_result($result_id);  			} -			@mssql_free_result($result_id); +		} +		else +		{ +			$error = array( +				'message'	=> $this->connect_error, +				'code'		=> '', +			);  		}  		return $error; diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 2ecc42cadf..04501cce8b 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -32,6 +32,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);  class dbal_mssql_odbc extends dbal  {  	var $last_query_text = ''; +	var $connect_error = '';  	/**  	* Connect to server @@ -68,7 +69,24 @@ class dbal_mssql_odbc extends dbal  			@ini_set('odbc.defaultlrl', $max_size);  		} -		$this->db_connect_id = ($this->persistency) ? @odbc_pconnect($this->server, $this->user, $sqlpassword) : @odbc_connect($this->server, $this->user, $sqlpassword); +		if ($this->persistency) +		{ +			if (!function_exists('odbc_pconnect')) +			{ +				$this->connect_error = 'odbc_pconnect function does not exist, is odbc extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @odbc_pconnect($this->server, $this->user, $sqlpassword); +		} +		else +		{ +			if (!function_exists('odbc_connect')) +			{ +				$this->connect_error = 'odbc_connect function does not exist, is odbc extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @odbc_connect($this->server, $this->user, $sqlpassword); +		}  		return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');  	} @@ -342,10 +360,22 @@ class dbal_mssql_odbc extends dbal  	*/  	function _sql_error()  	{ -		return array( -			'message'	=> @odbc_errormsg(), -			'code'		=> @odbc_error() -		); +		if (function_exists('odbc_errormsg')) +		{ +			$error = array( +				'message'	=> @odbc_errormsg(), +				'code'		=> @odbc_error(), +			); +		} +		else +		{ +			$error = array( +				'message'	=> $this->connect_error, +				'code'		=> '', +			); +		} + +		return $error;  	}  	/** diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index 3ad0ff3e11..b91372ac61 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -199,16 +199,18 @@ class dbal_mssqlnative extends dbal  	var $m_insert_id = NULL;  	var $last_query_text = '';  	var $query_options = array(); +	var $connect_error = '';  	/**  	* Connect to server  	*/  	function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)  	{ -		# Test for driver support, to avoid suppressed fatal error +		// Test for driver support, to avoid suppressed fatal error  		if (!function_exists('sqlsrv_connect'))  		{ -			trigger_error('Native MS SQL Server driver for PHP is missing or needs to be updated. Version 1.1 or later is required to install phpBB3. You can download the driver from: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx\n', E_USER_ERROR); +			$this->connect_error = 'Native MS SQL Server driver for PHP is missing or needs to be updated. Version 1.1 or later is required to install phpBB3. You can download the driver from: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx'; +			return $this->sql_error('');  		}  		//set up connection variables @@ -514,31 +516,43 @@ class dbal_mssqlnative extends dbal  	*/  	function _sql_error()  	{ -		$errors = @sqlsrv_errors(SQLSRV_ERR_ERRORS); -		$error_message = ''; -		$code = 0; - -		if ($errors != null) +		if (function_exists('sqlsrv_errors'))  		{ -			foreach ($errors as $error) +			$errors = @sqlsrv_errors(SQLSRV_ERR_ERRORS); +			$error_message = ''; +			$code = 0; + +			if ($errors != null) +			{ +				foreach ($errors as $error) +				{ +					$error_message .= "SQLSTATE: " . $error[ 'SQLSTATE'] . "\n"; +					$error_message .= "code: " . $error[ 'code'] . "\n"; +					$code = $error['code']; +					$error_message .= "message: " . $error[ 'message'] . "\n"; +				} +				$this->last_error_result = $error_message; +				$error = $this->last_error_result; +			} +			else  			{ -				$error_message .= "SQLSTATE: ".$error[ 'SQLSTATE']."\n"; -				$error_message .= "code: ".$error[ 'code']."\n"; -				$code = $error['code']; -				$error_message .= "message: ".$error[ 'message']."\n"; +				$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();  			} -			$this->last_error_result = $error_message; -			$error = $this->last_error_result; + +			$error = array( +				'message'	=> $error, +				'code'		=> $code, +			);  		}  		else  		{ -			$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); +			$error = array( +				'message'	=> $this->connect_error, +				'code'		=> '', +			);  		} -		return array( -			'message'	=> $error, -			'code'		=> $code, -		); +		return $error;  	}  	/** diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 1ccb785150..252cb20bd4 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -30,6 +30,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);  class dbal_mysql extends dbal  {  	var $multi_insert = true; +	var $connect_error = '';  	/**  	* Connect to server @@ -44,7 +45,24 @@ class dbal_mysql extends dbal  		$this->sql_layer = 'mysql4'; -		$this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); +		if ($this->persistency) +		{ +			if (!function_exists('mysql_pconnect')) +			{ +				$this->connect_error = 'mysql_pconnect function does not exist, is mysql extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @mysql_pconnect($this->server, $this->user, $sqlpassword); +		} +		else +		{ +			if (!function_exists('mysql_connect')) +			{ +				$this->connect_error = 'mysql_connect function does not exist, is mysql extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); +		}  		if ($this->db_connect_id && $this->dbname != '')  		{ @@ -419,18 +437,29 @@ class dbal_mysql extends dbal  	*/  	function _sql_error()  	{ -		if (!$this->db_connect_id) +		if ($this->db_connect_id) +		{ +			$error = array( +				'message'	=> @mysql_error($this->db_connect_id), +				'code'		=> @mysql_errno($this->db_connect_id), +			); +		} +		else if (function_exists('mysql_error'))  		{ -			return array( +			$error = array(  				'message'	=> @mysql_error(), -				'code'		=> @mysql_errno() +				'code'		=> @mysql_errno(), +			); +		} +		else +		{ +			$error = array( +				'message'	=> $this->connect_error, +				'code'		=> '',  			);  		} -		return array( -			'message'	=> @mysql_error($this->db_connect_id), -			'code'		=> @mysql_errno($this->db_connect_id) -		); +		return $error;  	}  	/** diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index a311b8cda6..69f1d26a40 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -27,12 +27,19 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);  class dbal_mysqli extends dbal  {  	var $multi_insert = true; +	var $connect_error = '';  	/**  	* Connect to server  	*/  	function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false , $new_link = false)  	{ +		if (!function_exists('mysqli_connect')) +		{ +			$this->connect_error = 'mysqli_connect function does not exist, is mysqli extension installed?'; +			return $this->sql_error(''); +		} +  		// Mysqli extension supports persistent connection since PHP 5.3.0  		$this->persistency = (version_compare(PHP_VERSION, '5.3.0', '>=')) ? $persistency : false;  		$this->user = $sqluser; @@ -416,18 +423,29 @@ class dbal_mysqli extends dbal  	*/  	function _sql_error()  	{ -		if (!$this->db_connect_id) +		if ($this->db_connect_id) +		{ +			$error = array( +				'message'	=> @mysqli_error($this->db_connect_id), +				'code'		=> @mysqli_errno($this->db_connect_id) +			); +		} +		else if (function_exists('mysqli_connect_error'))  		{ -			return array( +			$error = array(  				'message'	=> @mysqli_connect_error(), -				'code'		=> @mysqli_connect_errno() +				'code'		=> @mysqli_connect_errno(), +			); +		} +		else +		{ +			$error = array( +				'message'	=> $this->connect_error, +				'code'		=> '',  			);  		} -		return array( -			'message'	=> @mysqli_error($this->db_connect_id), -			'code'		=> @mysqli_errno($this->db_connect_id) -		); +		return $error;  	}  	/** diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 62b36aa8bf..4a7a4ecc8c 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -25,6 +25,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);  class dbal_oracle extends dbal  {  	var $last_query_text = ''; +	var $connect_error = '';  	/**  	* Connect to server @@ -48,7 +49,33 @@ class dbal_oracle extends dbal  			$connect = $sqlserver . (($port) ? ':' . $port : '') . '/' . $database;  		} -		$this->db_connect_id = ($new_link) ? @ocinlogon($this->user, $sqlpassword, $connect, 'UTF8') : (($this->persistency) ? @ociplogon($this->user, $sqlpassword, $connect, 'UTF8') : @ocilogon($this->user, $sqlpassword, $connect, 'UTF8')); +		if ($new_link) +		{ +			if (!function_exists('ocinlogon')) +			{ +				$this->connect_error = 'ocinlogon function does not exist, is oci extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @ocinlogon($this->user, $sqlpassword, $connect, 'UTF8'); +		} +		else if ($this->persistency) +		{ +			if (!function_exists('ociplogon')) +			{ +				$this->connect_error = 'ociplogon function does not exist, is oci extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @ociplogon($this->user, $sqlpassword, $connect, 'UTF8'); +		} +		else +		{ +			if (!function_exists('ocilogon')) +			{ +				$this->connect_error = 'ocilogon function does not exist, is oci extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @ocilogon($this->user, $sqlpassword, $connect, 'UTF8'); +		}  		return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');  	} @@ -647,17 +674,27 @@ class dbal_oracle extends dbal  	*/  	function _sql_error()  	{ -		$error = @ocierror(); -		$error = (!$error) ? @ocierror($this->query_result) : $error; -		$error = (!$error) ? @ocierror($this->db_connect_id) : $error; - -		if ($error) +		if (function_exists('ocierror'))  		{ -			$this->last_error_result = $error; +			$error = @ocierror(); +			$error = (!$error) ? @ocierror($this->query_result) : $error; +			$error = (!$error) ? @ocierror($this->db_connect_id) : $error; + +			if ($error) +			{ +				$this->last_error_result = $error; +			} +			else +			{ +				$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); +			}  		}  		else  		{ -			$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array(); +			$error = array( +				'message'	=> $this->connect_error, +				'code'		=> '', +			);  		}  		return $error; diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 8de72fd394..557b057cce 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -25,6 +25,8 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);  */  class dbal_sqlite extends dbal  { +	var $connect_error = ''; +  	/**  	* Connect to server  	*/ @@ -36,7 +38,24 @@ class dbal_sqlite extends dbal  		$this->dbname = $database;  		$error = ''; -		$this->db_connect_id = ($this->persistency) ? @sqlite_popen($this->server, 0666, $error) : @sqlite_open($this->server, 0666, $error); +		if ($this->persistency) +		{ +			if (!function_exists('sqlite_popen')) +			{ +				$this->connect_error = 'sqlite_popen function does not exist, is sqlite extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @sqlite_popen($this->server, 0666, $error); +		} +		else +		{ +			if (!function_exists('sqlite_open')) +			{ +				$this->connect_error = 'sqlite_open function does not exist, is sqlite extension installed?'; +				return $this->sql_error(''); +			} +			$this->db_connect_id = @sqlite_open($this->server, 0666, $error); +		}  		if ($this->db_connect_id)  		{ @@ -281,10 +300,22 @@ class dbal_sqlite extends dbal  	*/  	function _sql_error()  	{ -		return array( -			'message'	=> @sqlite_error_string(@sqlite_last_error($this->db_connect_id)), -			'code'		=> @sqlite_last_error($this->db_connect_id) -		); +		if (function_exists('sqlite_error_string')) +		{ +			$error = array( +				'message'	=> @sqlite_error_string(@sqlite_last_error($this->db_connect_id)), +				'code'		=> @sqlite_last_error($this->db_connect_id), +			); +		} +		else +		{ +			$error = array( +				'message'	=> $this->connect_error, +				'code'		=> '', +			); +		} + +		return $error;  	}  	/**  | 
