From af43ed655bf31ae4b9ef999e0a95eeae67724597 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 6 Mar 2011 20:55:41 -0500 Subject: [ticket/10057] Split statements in firebird dbal for readability. PHPBB3-10057 --- phpBB/includes/db/firebird.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/db/firebird.php') diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 6f60dd5dad..2f17b00b3f 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -53,9 +53,23 @@ class dbal_firebird extends dbal $use_database = $this->server . ':' . $this->dbname; } - $this->db_connect_id = ($this->persistency) ? @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); + if ($this->persistency) + { + $this->db_connect_id = @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3); + } + else + { + $this->db_connect_id = @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); + } - $this->service_handle = (function_exists('ibase_service_attach') && $this->server) ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; + if (function_exists('ibase_service_attach') && $this->server) + { + $this->service_handle = @ibase_service_attach($this->server, $this->user, $sqlpassword); + } + else + { + $thih->service_handle = false; + } return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } -- cgit v1.2.1 From 4d92f9bb2eea82a9af36401649c318623d39307f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 6 Mar 2011 21:03:24 -0500 Subject: [ticket/10057] Check for interbase function existence. Calling nonexistent functions with @ destroys the script with no feedback as to the cause of the error. Check whether interbase functions exist before calling them. PHPBB3-10057 --- phpBB/includes/db/firebird.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/includes/db/firebird.php') diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 2f17b00b3f..d1d88ffe42 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -55,10 +55,18 @@ class dbal_firebird extends dbal if ($this->persistency) { + if (!function_exists('ibase_pconnect')) + { + return $this->sql_error('ibase_pconnect function does not exist, is interbase extension installed?'); + } $this->db_connect_id = @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3); } else { + if (!function_exists('ibase_connect')) + { + return $this->sql_error('ibase_connect function does not exist, is interbase extension installed?'); + } $this->db_connect_id = @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); } -- cgit v1.2.1 From edc1deaa3afcadab82d404e705e162a9f3fa26c5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 6 Mar 2011 23:07:48 -0500 Subject: [ticket/10057] Skip ibase_service_attach if firebird connection failed. ibase_errmsg works for the most recent call. If the connection fails, any error message is clobbered by ibase_service_attach call. PHPBB3-10057 --- phpBB/includes/db/firebird.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/db/firebird.php') diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index d1d88ffe42..660acb35db 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -70,7 +70,9 @@ class dbal_firebird extends dbal $this->db_connect_id = @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); } - if (function_exists('ibase_service_attach') && $this->server) + // Do not call ibase_service_attach if connection failed, + // otherwise error message from ibase_(p)connect call will be clobbered. + if ($this->db_connect_id && function_exists('ibase_service_attach') && $this->server) { $this->service_handle = @ibase_service_attach($this->server, $this->user, $sqlpassword); } -- cgit v1.2.1 From 7acbf98692dfe4b3bf1ca103a1fa90d7f51d3c1b Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 7 Mar 2011 09:04:01 -0500 Subject: [ticket/10057] Fixed wrong usage of sql_error again, in firebird. This necessitates adding connect_error property to firebird. PHPBB3-10057 --- phpBB/includes/db/firebird.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/db/firebird.php') diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 660acb35db..fb820b4894 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -28,6 +28,7 @@ class dbal_firebird extends dbal var $last_query_text = ''; var $service_handle = false; var $affected_rows = 0; + var $connect_error = ''; /** * Connect to server @@ -57,7 +58,8 @@ class dbal_firebird extends dbal { if (!function_exists('ibase_pconnect')) { - return $this->sql_error('ibase_pconnect function does not exist, is interbase extension installed?'); + $this->connect_error = 'ibase_pconnect function does not exist, is interbase extension installed?'; + return $this->sql_error(''); } $this->db_connect_id = @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3); } @@ -65,7 +67,8 @@ class dbal_firebird extends dbal { if (!function_exists('ibase_connect')) { - return $this->sql_error('ibase_connect function does not exist, is interbase extension installed?'); + $this->connect_error = 'ibase_connect function does not exist, is interbase extension installed?'; + return $this->sql_error(''); } $this->db_connect_id = @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); } -- cgit v1.2.1 From 020d06cdaac13372feef615b8689ad2526733243 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 7 Mar 2011 09:09:40 -0500 Subject: [ticket/10057] Handle the case of missing interbase extension better. PHPBB3-10057 --- phpBB/includes/db/firebird.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/db/firebird.php') diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index fb820b4894..6786edb964 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -498,8 +498,24 @@ class dbal_firebird extends dbal */ function _sql_error() { + // Need special handling here because ibase_errmsg returns + // connection errors, however if the interbase extension + // is not installed then ibase_errmsg does not exist and + // we cannot call it. + if (function_exists('ibase_errmsg')) + { + $msg = @ibase_errmsg(); + if (!$msg) + { + $msg = $this->connect_error; + } + } + else + { + $msg = $this->connect_error; + } return array( - 'message' => @ibase_errmsg(), + 'message' => $msg, 'code' => (@function_exists('ibase_errcode') ? @ibase_errcode() : '') ); } -- cgit v1.2.1 From 87e3560c30365d757280f6ef6f067c29c1f9c5f0 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 8 Mar 2011 19:48:56 -0500 Subject: [ticket/10057] Fixes for a bunch of small problems. PHPBB3-10057 --- phpBB/includes/db/firebird.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/firebird.php') diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 6786edb964..7e3f15ed1d 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -81,7 +81,7 @@ class dbal_firebird extends dbal } else { - $thih->service_handle = false; + $this->service_handle = false; } return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); -- cgit v1.2.1