X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fdba.php;h=49b325cf7b544dfe72a79f210cfe992359f793a0;hb=1fb097951d3769b37a870ea498998b662f261e3f;hp=b05a1cabf48b8dce79ac22609d4cea389e433062;hpb=6480fd73a7c24b939d4b25ffacfdab0c8bb9c930;p=friendica.git diff --git a/include/dba.php b/include/dba.php index b05a1cabf4..49b325cf7b 100644 --- a/include/dba.php +++ b/include/dba.php @@ -19,13 +19,32 @@ class dba { public $connected = false; function __construct($server,$user,$pass,$db,$install = false) { + + $server = trim($server); + $user = trim($user); + $pass = trim($pass); + $db = trim($db); + + if($install) { + if(strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) { + if(! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) { + notice( sprintf( t('Cannot locate DNS info for database server \'%s\''), $server)); + $this->connected = false; + $this->db = null; + return; + } + } + } + $this->db = @new mysqli($server,$user,$pass,$db); - if((mysqli_connect_errno()) && (! $install)) { + if(! mysqli_connect_errno()) { + $this->connected = true; + } + else { $this->db = null; - system_unavailable(); + if(! $install) + system_unavailable(); } - else - $this->connected = true; } public function getdb() { @@ -34,7 +53,7 @@ class dba { public function q($sql) { - if(! $this->db ) + if((! $this->db) || (! $this->connected)) return false; $result = @$this->db->query($sql); @@ -59,7 +78,7 @@ class dba { } else { - /* + /** * If dbfail.out exists, we will write any failed calls directly to it, * regardless of any logging that may or may nor be in effect. * These usually indicate SQL syntax errors that need to be resolved. @@ -92,7 +111,8 @@ class dba { } public function escape($str) { - return @$this->db->real_escape_string($str); + if($this->db && $this->connected) + return @$this->db->real_escape_string($str); } function __destruct() {