From 7d47152564c004418867ecd6f7d7e93cb216e27a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 22 Jul 2018 18:53:46 +0200 Subject: [PATCH] Fixed E_NOTICE in boot.php and DBA class (#5430) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Fixes: - fixed missing variable $port (MySQL: 3306) - "imported" mysqli class Signed-off-by: Roland Häder * Fixed: - better use `false` and `$port > 0` * And better only provide `$port` when larger zero. * Initialize `$port` with zero value (int) and not `false` (bool). * Removed duplicate mysqli "import". * `$post_update` is no longer used. Instead `$prefix` needs to be checked. --- boot.php | 8 ++++++-- src/Database/DBA.php | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/boot.php b/boot.php index 4c3a8c5ca8..17caa19033 100644 --- a/boot.php +++ b/boot.php @@ -768,16 +768,20 @@ function run_update_function($x, $prefix) return false; } else { Config::set('database', $funcname, 'success'); - if ($post_update) { + + if ($prefix == 'update') { Config::set('system', 'build', $x); } + return true; } } else { Config::set('database', $funcname, 'success'); - if ($post_update) { + + if ($prefix == 'update') { Config::set('system', 'build', $x); } + return true; } } diff --git a/src/Database/DBA.php b/src/Database/DBA.php index 51b2c8898e..3fae84c766 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -8,10 +8,10 @@ namespace Friendica\Database; use Friendica\Core\System; use Friendica\Util\DateTimeFormat; +use mysqli; use PDO; use PDOException; use PDOStatement; -use mysqli; /** * @class MySQL database class @@ -50,6 +50,7 @@ class DBA self::$db_name = $db; self::$db_charset = $charset; + $port = 0; $serveraddr = trim($serveraddr); $serverdata = explode(':', $serveraddr); @@ -73,7 +74,7 @@ class DBA self::$driver = 'pdo'; $connect = "mysql:host=".$server.";dbname=".$db; - if (isset($port)) { + if ($port > 0) { $connect .= ";port=".$port; } @@ -89,9 +90,15 @@ class DBA } } - if (!self::$connected && class_exists('mysqli')) { + if (!self::$connected && class_exists('\mysqli')) { self::$driver = 'mysqli'; - self::$db = @new mysqli($server, $user, $pass, $db, $port); + + if ($port > 0) { + self::$db = @new mysqli($server, $user, $pass, $db, $port); + } else { + self::$db = @new mysqli($server, $user, $pass, $db); + } + if (!mysqli_connect_errno()) { self::$connected = true; -- 2.39.5