From fff87a117b1680e8a315722284e280daabda248a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 23 Mar 2005 22:10:38 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20Ajout=20test=20si=20param=E8tre=20host?= =?UTF-8?q?=20invalide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/mysql.lib.php | 19 ++++++++++++------- htdocs/lib/pgsql.lib.php | 17 +++++++++++------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/htdocs/lib/mysql.lib.php b/htdocs/lib/mysql.lib.php index a55c4359f21..3e6fb50588a 100644 --- a/htdocs/lib/mysql.lib.php +++ b/htdocs/lib/mysql.lib.php @@ -84,15 +84,21 @@ class DoliDb global $conf; $this->transaction_opened=0; - if ($host == '') $host = $conf->db->host; - if ($user == '') $user = $conf->db->user; - if ($pass == '') $pass = $conf->db->pass; - if ($name == '') $name = $conf->db->name; + if (! $host) $host = $conf->db->host; + if (! $user) $user = $conf->db->user; + if (! $pass) $pass = $conf->db->pass; + if (! $name) $name = $conf->db->name; //print "Name DB: $host,$user,$pass,$name
"; - + if (! $host) + { + $this->connected = 0; + $this->ok = 0; + dolibarr_syslog("DoliDB::DoliDB : Erreur Connect, wrong host parameters"); + return $this->ok; + } + // Essai connexion serveur - $this->db = $this->connect($host, $user, $pass, $newlink); if ($this->db) @@ -108,7 +114,6 @@ class DoliDb } // Si connexion serveur ok et si connexion base demandée, on essaie connexion base - if ($this->connected && $name) { if ($this->select_db($name) == 1) diff --git a/htdocs/lib/pgsql.lib.php b/htdocs/lib/pgsql.lib.php index 4a2cdd31ad6..753756b53df 100644 --- a/htdocs/lib/pgsql.lib.php +++ b/htdocs/lib/pgsql.lib.php @@ -68,15 +68,21 @@ class DoliDb global $conf; $this->transaction_opened=0; - if ($host == '') $host = $conf->db->host; - if ($user == '') $user = $conf->db->user; - if ($pass == '') $pass = $conf->db->pass; - if ($name == '') $name = $conf->db->name; + if (! $host) $host = $conf->db->host; + if (! $user) $user = $conf->db->user; + if (! $pass) $pass = $conf->db->pass; + if (! $name) $name = $conf->db->name; //print "Name DB: $host,$user,$pass,$name
"; + if (! $host) + { + $this->connected = 0; + $this->ok = 0; + dolibarr_syslog("DoliDB::DoliDB : Erreur Connect, wrong host parameters"); + return $this->ok; + } // Essai connexion serveur - $this->db = $this->connect($host, $user, $pass, $name); if ($this->db) @@ -91,7 +97,6 @@ class DoliDb } // Si connexion serveur ok et si connexion base demandée, on essaie connexion base - if ($this->connected && $name) { if ($this->select_db($name) == 1)