Les variables d'état de la fonction connect (this->connected,this->database_selected et this->ok n'était pas toujours toutes les 3 positionnées).

This commit is contained in:
Laurent Destailleur 2004-02-23 22:40:27 +00:00
parent f2560aa0d7
commit f9411c30ed

View File

@ -26,55 +26,68 @@ class DoliDb {
var $db, $results, $ok, $connected, $database_selected; var $db, $results, $ok, $connected, $database_selected;
Function DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '') 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; global $conf;
// print "Name DB : $host, $user, $pass, $name<br>"; if ($host == '')
{
$host = $conf->db->host;
}
if ($host == '') if ($user == '')
{ {
$host = $conf->db->host; $user = $conf->db->user;
} }
if ($user == '') if ($pass == '')
{ {
$user = $conf->db->user; $pass = $conf->db->pass;
} }
if ($pass == '') if ($name == '')
{ {
$pass = $conf->db->pass; $name = $conf->db->name;
} }
if ($name == '') //print "Name DB: $host,$user,$pass,$name<br>";
{
$name = $conf->db->name;
}
$this->db = $this->connect($host, $user, $pass); // Essai connexion serveur
if ($this->db) $this->db = $this->connect($host, $user, $pass);
{ if ($this->db)
$this->connected = 1; {
} $this->connected = 1;
else $this->ok = 1;
{ }
$this->connected = 0; else
return 0; {
} $this->connected = 0;
$this->ok = 0;
}
$ret = $this->select_db($name); // Si connexion serveur ok et si connexion base demandée, on essaie connexion base
if ($this->connected && $name) {
if ($ret == 1) if ($this->select_db($name) == 1)
{ {
$this->database_selected = 1; $this->database_selected = 1;
$this->ok = 1; $this->ok = 1;
} }
else else
{ {
$this->database_selected = 0; $this->database_selected = 0;
$this->ok = 0; $this->ok = 0;
} }
return $ret;
}
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) Function connect($host, $login, $passwd)
{ {
$this->db = @mysql_connect($host, $login, $passwd); $this->db = @mysql_connect($host, $login, $passwd);
//print "Resultat fonction connect: ".$this->db;
return $this->db; return $this->db;
} }
/* /*