From f9411c30edeb558ad924fe1bf479c0c7a6bcbd32 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 23 Feb 2004 22:40:27 +0000 Subject: [PATCH] =?UTF-8?q?Les=20variables=20d'=E9tat=20de=20la=20fonction?= =?UTF-8?q?=20connect=20(this->connected,this->database=5Fselected=20et=20?= =?UTF-8?q?this->ok=20n'=E9tait=20pas=20toujours=20toutes=20les=203=20posi?= =?UTF-8?q?tionn=E9es).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/mysql.lib.php | 102 ++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/htdocs/lib/mysql.lib.php b/htdocs/lib/mysql.lib.php index 638c747764a..a71a1088cba 100644 --- a/htdocs/lib/mysql.lib.php +++ b/htdocs/lib/mysql.lib.php @@ -26,55 +26,68 @@ class DoliDb { var $db, $results, $ok, $connected, $database_selected; Function DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '') + // Se connecte au serveur et éventuellement à une base (si spécifié) + // Renvoie 1 en cas de succès, 0 sinon { global $conf; - // print "Name DB : $host, $user, $pass, $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 == '') - { - $host = $conf->db->host; - } - - if ($user == '') - { - $user = $conf->db->user; - } - - if ($pass == '') - { - $pass = $conf->db->pass; - } - - if ($name == '') - { - $name = $conf->db->name; - } + // Essai connexion serveur + $this->db = $this->connect($host, $user, $pass); + if ($this->db) + { + $this->connected = 1; + $this->ok = 1; + } + else + { + $this->connected = 0; + $this->ok = 0; + } - $this->db = $this->connect($host, $user, $pass); - if ($this->db) - { - $this->connected = 1; - } - else - { - $this->connected = 0; - return 0; - } - - $ret = $this->select_db($name); - - if ($ret == 1) - { - $this->database_selected = 1; - $this->ok = 1; - } - else - { - $this->database_selected = 0; - $this->ok = 0; - } - return $ret; + // Si connexion serveur ok et si connexion base demandée, on essaie connexion base + if ($this->connected && $name) { + + if ($this->select_db($name) == 1) + { + $this->database_selected = 1; + $this->ok = 1; + } + else + { + $this->database_selected = 0; + $this->ok = 0; + } + + } + else { + // Pas de selection de base demandée, mais tout est ok + $this->database_selected = 0; + $this->ok = 1; + } + + return $this->ok; } /* * @@ -89,6 +102,7 @@ class DoliDb { Function connect($host, $login, $passwd) { $this->db = @mysql_connect($host, $login, $passwd); + //print "Resultat fonction connect: ".$this->db; return $this->db; } /*