From f2e179b750d09dc0ace990d8da79b79380881392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 29 Jul 2016 12:21:06 +0200 Subject: [PATCH] Simplify DBI code as $server no longer can be null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/dbi/DBIExtension.php | 2 +- libraries/dbi/DBIMysql.php | 17 +++++------------ libraries/dbi/DBIMysqli.php | 33 ++++++++++----------------------- 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/libraries/dbi/DBIExtension.php b/libraries/dbi/DBIExtension.php index 6d90479c97..f871c65b67 100644 --- a/libraries/dbi/DBIExtension.php +++ b/libraries/dbi/DBIExtension.php @@ -25,7 +25,7 @@ interface DBIExtension * @return mixed false on error or a connection object on success */ public function connect( - $user, $password, $server = null + $user, $password, $server ); /** diff --git a/libraries/dbi/DBIMysql.php b/libraries/dbi/DBIMysql.php index 511fd3b38d..0546ab9d49 100644 --- a/libraries/dbi/DBIMysql.php +++ b/libraries/dbi/DBIMysql.php @@ -99,7 +99,7 @@ class DBIMysql implements DBIExtension * @return mixed false on error or a mysqli object on success */ public function connect( - $user, $password, $server = null + $user, $password, $server ) { if ($server['port'] === 0) { $server_port = ''; @@ -130,20 +130,13 @@ class DBIMysql implements DBIExtension $client_flags |= MYSQL_CLIENT_SSL; } - if (! $server) { + if (!isset($server['host'])) { + $link = $this->_realConnect($server_socket, $user, $password, null); + } else { $link = $this->_realConnect( $server['host'] . $server_port . $server_socket, - $user, $password, empty($client_flags) ? null : $client_flags + $user, $password, null ); - } else { - if (!isset($server['host'])) { - $link = $this->_realConnect($server_socket, $user, $password, null); - } else { - $link = $this->_realConnect( - $server['host'] . $server_port . $server_socket, - $user, $password, null - ); - } } return $link; } diff --git a/libraries/dbi/DBIMysqli.php b/libraries/dbi/DBIMysqli.php index 6eb934c0b5..485b649a76 100644 --- a/libraries/dbi/DBIMysqli.php +++ b/libraries/dbi/DBIMysqli.php @@ -117,7 +117,7 @@ class DBIMysqli implements DBIExtension * @return mixed false on error or a mysqli object on success */ public function connect( - $user, $password, $server = null + $user, $password, $server ) { if ($server) { $server['host'] = (empty($server['host'])) @@ -166,28 +166,15 @@ class DBIMysqli implements DBIExtension } } - if (! $server) { - $return_value = $this->_realConnect( - $link, - $server['host'], - $user, - $password, - false, - $server['port'], - $server['socket'], - $client_flags - ); - } else { - $return_value = $this->_realConnect( - $link, - $server['host'], - $user, - $password, - false, - $server['port'], - $server['socket'] - ); - } + $return_value = $this->_realConnect( + $link, + $server['host'], + $user, + $password, + false, + $server['port'], + $server['socket'] + ); if ($return_value === false || is_null($return_value)) { return false;