From 025a95ea909d449e14cb22564983fb005e3f8c06 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Wed, 9 Mar 2011 21:50:45 -0500
Subject: [ticket/10205] Account for potentially missing extensions in dbal.

PHPBB3-10205
---
 phpBB/includes/db/mssql_odbc.php | 20 +++++++++++++++++++-
 phpBB/includes/db/mysql.php      | 20 +++++++++++++++++++-
 phpBB/includes/db/mysqli.php     |  7 +++++++
 phpBB/includes/db/oracle.php     | 29 ++++++++++++++++++++++++++++-
 phpBB/includes/db/sqlite.php     | 21 ++++++++++++++++++++-
 5 files changed, 93 insertions(+), 4 deletions(-)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index 2ecc42cadf..dabdbd1a44 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('');
 	}
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index 1ccb785150..ae36fe6425 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 != '')
 		{
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index a311b8cda6..98b659723f 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;
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index 62b36aa8bf..42f5de1b24 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('');
 	}
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index 8de72fd394..be0ad4fc8f 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)
 		{
-- 
cgit v1.2.1


From 1a7e2211c35218094e30ddc399d4aa6b45fe75f4 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Tue, 4 Dec 2012 04:06:30 -0500
Subject: [ticket/10205] Avoid calling mysqli functions when mysqli is missing.

PHPBB3-10205
---
 phpBB/includes/db/mysqli.php | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index 98b659723f..cd82a12b58 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -425,10 +425,20 @@ class dbal_mysqli extends dbal
 	{
 		if (!$this->db_connect_id)
 		{
-			return array(
-				'message'	=> @mysqli_connect_error(),
-				'code'		=> @mysqli_connect_errno()
-			);
+			if (function_exists('mysqli_connect_error'))
+			{
+				return array(
+					'message'	=> @mysqli_connect_error(),
+					'code'		=> @mysqli_connect_errno(),
+				);
+			}
+			else
+			{
+				return array(
+					'message'	=> $this->connect_error,
+					'code'		=> '',
+				);
+			}
 		}
 
 		return array(
-- 
cgit v1.2.1


From 9f549e8249acbd82b68e961a6e0a31de47d9ca32 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Tue, 4 Dec 2012 04:50:41 -0500
Subject: [ticket/10205] Fix remaining db drivers.

PHPBB3-10205
---
 phpBB/includes/db/mssql.php      | 58 +++++++++++++++++++++++-----------------
 phpBB/includes/db/mssql_odbc.php | 18 ++++++++++---
 phpBB/includes/db/mysql.php      | 18 ++++++++++---
 phpBB/includes/db/oracle.php     | 24 ++++++++++++-----
 phpBB/includes/db/sqlite.php     | 18 ++++++++++---
 5 files changed, 93 insertions(+), 43 deletions(-)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index b7178593dc..bc0a870885 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -355,34 +355,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)
 			{
-				$error['message'] .= '<br />' . $row['message'];
+				$row = @mssql_fetch_assoc($result_id);
+				$error['code'] = $row['code'];
+				@mssql_free_result($result_id);
 			}
-			@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)
+			{
+				$row = @mssql_fetch_assoc($result_id);
+				if (!empty($row['message']))
+				{
+					$error['message'] .= '<br />' . $row['message'];
+				}
+				@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 dabdbd1a44..e1234389df 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -360,10 +360,20 @@ class dbal_mssql_odbc extends dbal
 	*/
 	function _sql_error()
 	{
-		return array(
-			'message'	=> @odbc_errormsg(),
-			'code'		=> @odbc_error()
-		);
+		if (function_exists('odbc_errormsg'))
+		{
+			return array(
+				'message'	=> @odbc_errormsg(),
+				'code'		=> @odbc_error()
+			);
+		}
+		else
+		{
+			return array(
+				'message'	=> $this->connect_error,
+				'code'		=> '',
+			);
+		}
 	}
 
 	/**
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index ae36fe6425..7314e92087 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -439,10 +439,20 @@ class dbal_mysql extends dbal
 	{
 		if (!$this->db_connect_id)
 		{
-			return array(
-				'message'	=> @mysql_error(),
-				'code'		=> @mysql_errno()
-			);
+			if (function_exists('mysql_error'))
+			{
+				return array(
+					'message'	=> @mysql_error(),
+					'code'		=> @mysql_errno()
+				);
+			}
+			else
+			{
+				return array(
+					'message'	=> $this->connect_error,
+					'code'		=> '',
+				);
+			}
 		}
 
 		return array(
diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index 42f5de1b24..b234d8b45e 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -674,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 be0ad4fc8f..3c9b2cce34 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -300,10 +300,20 @@ 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'))
+		{
+			return array(
+				'message'	=> @sqlite_error_string(@sqlite_last_error($this->db_connect_id)),
+				'code'		=> @sqlite_last_error($this->db_connect_id)
+			);
+		}
+		else
+		{
+			return array(
+				'message'	=> $this->connect_error,
+				'code'		=> '',
+			);
+		}
 	}
 
 	/**
-- 
cgit v1.2.1


From 40db60e45f3d7af01a96f9da6b36db2606b3d147 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Tue, 4 Dec 2012 16:07:02 -0500
Subject: [ticket/10205] Fix a parse error in oracle driver.

PHPBB3-10205
---
 phpBB/includes/db/oracle.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php
index b234d8b45e..4a7a4ecc8c 100644
--- a/phpBB/includes/db/oracle.php
+++ b/phpBB/includes/db/oracle.php
@@ -74,7 +74,7 @@ class dbal_oracle extends dbal
 				$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'));
+			$this->db_connect_id = @ocilogon($this->user, $sqlpassword, $connect, 'UTF8');
 		}
 
 		return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
-- 
cgit v1.2.1


From de2fe1a308b08af868f22d6d9c0b7007f66de676 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Tue, 4 Dec 2012 16:12:31 -0500
Subject: [ticket/10205] Convert mssqlnative driver to the same logic.

PHPBB3-10205
---
 phpBB/includes/db/mssqlnative.php | 52 ++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 20 deletions(-)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php
index 3ad0ff3e11..e5de30faf6 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,41 @@ 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)
 			{
-				$error_message .= "SQLSTATE: ".$error[ 'SQLSTATE']."\n";
-				$error_message .= "code: ".$error[ 'code']."\n";
-				$code = $error['code'];
-				$error_message .= "message: ".$error[ 'message']."\n";
+				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;
 			}
-			$this->last_error_result = $error_message;
-			$error = $this->last_error_result;
+			else
+			{
+				$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();
+			}
+
+			return array(
+				'message'	=> $error,
+				'code'		=> $code,
+			);
 		}
 		else
 		{
-			$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();
+			return array(
+				'message'	=> $this->connect_error,
+				'code'		=> '',
+			);
 		}
-
-		return array(
-			'message'	=> $error,
-			'code'		=> $code,
-		);
 	}
 
 	/**
-- 
cgit v1.2.1


From dc521692f3c6d65b842a42f68bc727c8a36c9042 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Tue, 4 Dec 2012 16:14:39 -0500
Subject: [ticket/10205] Check for function existence in mssql connect method.

PHPBB3-10205
---
 phpBB/includes/db/mssql.php | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index bc0a870885..3792e82aa0 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;
-- 
cgit v1.2.1


From 89c9c9d4b0daa7308fd015e8a6fca6386a8b8016 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Tue, 4 Dec 2012 21:22:33 -0500
Subject: [ticket/10205] Cosmetic changes.

PHPBB3-10205
---
 phpBB/includes/db/mssql.php       | 2 +-
 phpBB/includes/db/mssql_odbc.php  | 2 +-
 phpBB/includes/db/mssqlnative.php | 6 +++---
 phpBB/includes/db/mysql.php       | 4 ++--
 phpBB/includes/db/sqlite.php      | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php
index 3792e82aa0..2dd95c2508 100644
--- a/phpBB/includes/db/mssql.php
+++ b/phpBB/includes/db/mssql.php
@@ -367,7 +367,7 @@ class dbal_mssql extends dbal
 		{
 			$error = array(
 				'message'	=> @mssql_get_last_message(),
-				'code'		=> ''
+				'code'		=> '',
 			);
 
 			// Get error code number
diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index e1234389df..47792d74ab 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -364,7 +364,7 @@ class dbal_mssql_odbc extends dbal
 		{
 			return array(
 				'message'	=> @odbc_errormsg(),
-				'code'		=> @odbc_error()
+				'code'		=> @odbc_error(),
 			);
 		}
 		else
diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php
index e5de30faf6..41ac0a1784 100644
--- a/phpBB/includes/db/mssqlnative.php
+++ b/phpBB/includes/db/mssqlnative.php
@@ -526,10 +526,10 @@ class dbal_mssqlnative extends dbal
 			{
 				foreach ($errors as $error)
 				{
-					$error_message .= "SQLSTATE: ".$error[ 'SQLSTATE']."\n";
-					$error_message .= "code: ".$error[ 'code']."\n";
+					$error_message .= "SQLSTATE: " . $error[ 'SQLSTATE'] . "\n";
+					$error_message .= "code: " . $error[ 'code'] . "\n";
 					$code = $error['code'];
-					$error_message .= "message: ".$error[ 'message']."\n";
+					$error_message .= "message: " . $error[ 'message'] . "\n";
 				}
 				$this->last_error_result = $error_message;
 				$error = $this->last_error_result;
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index 7314e92087..0125be0917 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -443,7 +443,7 @@ class dbal_mysql extends dbal
 			{
 				return array(
 					'message'	=> @mysql_error(),
-					'code'		=> @mysql_errno()
+					'code'		=> @mysql_errno(),
 				);
 			}
 			else
@@ -457,7 +457,7 @@ class dbal_mysql extends dbal
 
 		return array(
 			'message'	=> @mysql_error($this->db_connect_id),
-			'code'		=> @mysql_errno($this->db_connect_id)
+			'code'		=> @mysql_errno($this->db_connect_id),
 		);
 	}
 
diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php
index 3c9b2cce34..199b4eed23 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -304,7 +304,7 @@ class dbal_sqlite extends dbal
 		{
 			return array(
 				'message'	=> @sqlite_error_string(@sqlite_last_error($this->db_connect_id)),
-				'code'		=> @sqlite_last_error($this->db_connect_id)
+				'code'		=> @sqlite_last_error($this->db_connect_id),
 			);
 		}
 		else
-- 
cgit v1.2.1


From 597dea1e047b94f0a862f7f6e650771ffc780141 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Tue, 4 Dec 2012 21:32:02 -0500
Subject: [ticket/10205] Rewrite _sql_error implementations to have a single
 return.

PHPBB3-10205
---
 phpBB/includes/db/mssql_odbc.php  |  6 ++++--
 phpBB/includes/db/mssqlnative.php |  6 ++++--
 phpBB/includes/db/mysql.php       | 18 +++++++++++-------
 phpBB/includes/db/mysqli.php      | 18 +++++++++++-------
 phpBB/includes/db/sqlite.php      |  6 ++++--
 5 files changed, 34 insertions(+), 20 deletions(-)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php
index 47792d74ab..04501cce8b 100644
--- a/phpBB/includes/db/mssql_odbc.php
+++ b/phpBB/includes/db/mssql_odbc.php
@@ -362,18 +362,20 @@ class dbal_mssql_odbc extends dbal
 	{
 		if (function_exists('odbc_errormsg'))
 		{
-			return array(
+			$error = array(
 				'message'	=> @odbc_errormsg(),
 				'code'		=> @odbc_error(),
 			);
 		}
 		else
 		{
-			return array(
+			$error = array(
 				'message'	=> $this->connect_error,
 				'code'		=> '',
 			);
 		}
+
+		return $error;
 	}
 
 	/**
diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php
index 41ac0a1784..b91372ac61 100644
--- a/phpBB/includes/db/mssqlnative.php
+++ b/phpBB/includes/db/mssqlnative.php
@@ -539,18 +539,20 @@ class dbal_mssqlnative extends dbal
 				$error = (isset($this->last_error_result) && $this->last_error_result) ? $this->last_error_result : array();
 			}
 
-			return array(
+			$error = array(
 				'message'	=> $error,
 				'code'		=> $code,
 			);
 		}
 		else
 		{
-			return array(
+			$error = array(
 				'message'	=> $this->connect_error,
 				'code'		=> '',
 			);
 		}
+
+		return $error;
 	}
 
 	/**
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index 0125be0917..e638531f51 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -437,28 +437,32 @@ 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(),
 				);
 			}
 			else
 			{
-				return array(
+				$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 cd82a12b58..b2a43d35f9 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -423,28 +423,32 @@ 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(),
 				);
 			}
 			else
 			{
-				return array(
+				$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/sqlite.php b/phpBB/includes/db/sqlite.php
index 199b4eed23..557b057cce 100644
--- a/phpBB/includes/db/sqlite.php
+++ b/phpBB/includes/db/sqlite.php
@@ -302,18 +302,20 @@ class dbal_sqlite extends dbal
 	{
 		if (function_exists('sqlite_error_string'))
 		{
-			return array(
+			$error = array(
 				'message'	=> @sqlite_error_string(@sqlite_last_error($this->db_connect_id)),
 				'code'		=> @sqlite_last_error($this->db_connect_id),
 			);
 		}
 		else
 		{
-			return array(
+			$error = array(
 				'message'	=> $this->connect_error,
 				'code'		=> '',
 			);
 		}
+
+		return $error;
 	}
 
 	/**
-- 
cgit v1.2.1


From 5120f36a258ffcbffd5c10e9a1056d64ea794a16 Mon Sep 17 00:00:00 2001
From: Oleg Pudeyev <oleg@bsdpower.com>
Date: Tue, 4 Dec 2012 21:33:13 -0500
Subject: [ticket/10205] Reduce nesting in mysql drivers.

PHPBB3-10205
---
 phpBB/includes/db/mysql.php  | 25 +++++++++++--------------
 phpBB/includes/db/mysqli.php | 25 +++++++++++--------------
 2 files changed, 22 insertions(+), 28 deletions(-)

(limited to 'phpBB')

diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index e638531f51..252cb20bd4 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -444,22 +444,19 @@ class dbal_mysql extends dbal
 				'code'		=> @mysql_errno($this->db_connect_id),
 			);
 		}
+		else if (function_exists('mysql_error'))
+		{
+			$error = array(
+				'message'	=> @mysql_error(),
+				'code'		=> @mysql_errno(),
+			);
+		}
 		else
 		{
-			if (function_exists('mysql_error'))
-			{
-				$error = array(
-					'message'	=> @mysql_error(),
-					'code'		=> @mysql_errno(),
-				);
-			}
-			else
-			{
-				$error = array(
-					'message'	=> $this->connect_error,
-					'code'		=> '',
-				);
-			}
+			$error = array(
+				'message'	=> $this->connect_error,
+				'code'		=> '',
+			);
 		}
 
 		return $error;
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index b2a43d35f9..69f1d26a40 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -430,22 +430,19 @@ class dbal_mysqli extends dbal
 				'code'		=> @mysqli_errno($this->db_connect_id)
 			);
 		}
+		else if (function_exists('mysqli_connect_error'))
+		{
+			$error = array(
+				'message'	=> @mysqli_connect_error(),
+				'code'		=> @mysqli_connect_errno(),
+			);
+		}
 		else
 		{
-			if (function_exists('mysqli_connect_error'))
-			{
-				$error = array(
-					'message'	=> @mysqli_connect_error(),
-					'code'		=> @mysqli_connect_errno(),
-				);
-			}
-			else
-			{
-				$error = array(
-					'message'	=> $this->connect_error,
-					'code'		=> '',
-				);
-			}
+			$error = array(
+				'message'	=> $this->connect_error,
+				'code'		=> '',
+			);
 		}
 
 		return $error;
-- 
cgit v1.2.1