]> git.mxchange.org Git - friendica.git/commitdiff
Add meaningful return value to dba::connect
authorHypolite Petovan <mrpetovan@gmail.com>
Sun, 18 Mar 2018 09:15:14 +0000 (05:15 -0400)
committerHypolite Petovan <mrpetovan@gmail.com>
Sun, 18 Mar 2018 09:15:14 +0000 (05:15 -0400)
- Move System::unavailable call to index

include/dba.php
index.php

index af571f24582182fc70d442d38dd5ea048d35bc1f..586fc092fb764c51b9c54587f167b30570b51c20 100644 (file)
@@ -13,7 +13,7 @@ use Friendica\Util\DateTimeFormat;
  */
 
 class dba {
-       public static $connected = true;
+       public static $connected = false;
 
        private static $_server_info = '';
        private static $db;
@@ -48,8 +48,6 @@ class dba {
                $db = trim($db);
 
                if (!(strlen($server) && strlen($user))) {
-                       self::$connected = false;
-                       self::$db = null;
                        return false;
                }
 
@@ -57,8 +55,6 @@ class dba {
                        if (strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
                                if (! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
                                        self::$error = L10n::t('Cannot locate DNS info for database server \'%s\'', $server);
-                                       self::$connected = false;
-                                       self::$db = null;
                                        return false;
                                }
                        }
@@ -79,7 +75,6 @@ class dba {
                                self::$db = @new PDO($connect, $user, $pass);
                                self::$connected = true;
                        } catch (PDOException $e) {
-                               self::$connected = false;
                        }
                }
 
@@ -98,13 +93,10 @@ class dba {
                // No suitable SQL driver was found.
                if (!self::$connected) {
                        self::$db = null;
-                       if (!$install) {
-                               System::unavailable();
-                       }
                }
                $a->save_timestamp($stamp1, "network");
 
-               return true;
+               return self::$connected;
        }
 
        /**
index fba16263ab10c230ebb5b7bbc0327033a07509f9..a76057101a2f72596cc5c2b13555a5fd0ef85dc0 100644 (file)
--- a/index.php
+++ b/index.php
@@ -51,9 +51,13 @@ if (!$install) {
 require_once "include/dba.php";
 
 if (!$install) {
-       dba::connect($db_host, $db_user, $db_pass, $db_data, $install);
+       $result = dba::connect($db_host, $db_user, $db_pass, $db_data);
        unset($db_host, $db_user, $db_pass, $db_data);
 
+       if (!$result) {
+               System::unavailable();
+       }
+
        /**
         * Load configs from db. Overwrite configs from .htconfig.php
         */