forked from Wavyzz/dolibarr
fini d'adapter pour la documentation avec phpdocumentor
This commit is contained in:
@@ -42,161 +42,253 @@ class DoliDb {
|
|||||||
var $ERROR_DUPLICATE=1062;
|
var $ERROR_DUPLICATE=1062;
|
||||||
var $ERROR_TABLEEXISTS=1050;
|
var $ERROR_TABLEEXISTS=1050;
|
||||||
|
|
||||||
Function DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '')
|
|
||||||
// Se connecte au serveur et <20>ventuellement <20> une base (si sp<73>cifi<66>)
|
/**
|
||||||
|
* ouverture d'une connection vers le serveur et/ou une database
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $type
|
||||||
|
* @param string $host
|
||||||
|
* @param string $user
|
||||||
|
* @param string $pass
|
||||||
|
* @param string $name
|
||||||
|
*/
|
||||||
|
|
||||||
|
Function DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '')
|
||||||
|
|
||||||
|
// Se connecte au serveur et <20>ventuellement <20> une base (si sp<73>cifi<66>)
|
||||||
// Renvoie 1 en cas de succ<63>s, 0 sinon
|
// Renvoie 1 en cas de succ<63>s, 0 sinon
|
||||||
{
|
|
||||||
global $conf;
|
|
||||||
|
|
||||||
if ($host == '')
|
|
||||||
{
|
{
|
||||||
$host = $conf->db->host;
|
global $conf;
|
||||||
}
|
|
||||||
|
|
||||||
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<br>";
|
|
||||||
|
|
||||||
// Essai connexion serveur
|
if ($host == '')
|
||||||
$this->db = $this->connect($host, $user, $pass);
|
{
|
||||||
if ($this->db)
|
$host = $conf->db->host;
|
||||||
{
|
}
|
||||||
$this->connected = 1;
|
|
||||||
$this->ok = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->connected = 0;
|
|
||||||
$this->ok = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si connexion serveur ok et si connexion base demand<6E>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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if ($user == '')
|
||||||
else {
|
{
|
||||||
// Pas de selection de base demand<6E>e, mais tout est ok
|
$user = $conf->db->user;
|
||||||
$this->database_selected = 0;
|
}
|
||||||
$this->ok = 1;
|
|
||||||
}
|
if ($pass == '')
|
||||||
|
{
|
||||||
|
$pass = $conf->db->pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($name == '')
|
||||||
|
{
|
||||||
|
$name = $conf->db->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
//print "Name DB: $host,$user,$pass,$name<br>";
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si connexion serveur ok et si connexion base demand<6E>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<6E>e, mais tout est ok
|
||||||
|
|
||||||
|
$this->database_selected = 0;
|
||||||
|
$this->ok = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->ok;
|
return $this->ok;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*
|
/**
|
||||||
*/
|
* selectionne une database
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $database
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
Function select_db($database)
|
Function select_db($database)
|
||||||
{
|
{
|
||||||
return mysql_select_db($database, $this->db);
|
return mysql_select_db($database, $this->db);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*
|
/**
|
||||||
*/
|
* connection vers une database
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $host
|
||||||
|
* @param string $login
|
||||||
|
* @param string $passwd
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
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;
|
//print "Resultat fonction connect: ".$this->db;
|
||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*
|
/**
|
||||||
*/
|
* cr<63>ation d'une database
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $database
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
|
||||||
Function create_db($database)
|
Function create_db($database)
|
||||||
{
|
{
|
||||||
if (mysql_create_db ($database, $this->db))
|
if (mysql_create_db ($database, $this->db))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*
|
/**
|
||||||
*/
|
* copie d'une database
|
||||||
Function clone()
|
*
|
||||||
|
* @access public
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
|
Function clone()
|
||||||
{
|
{
|
||||||
$db2 = new DoliDb("", "", "", "", "");
|
$db2 = new DoliDb("", "", "", "", "");
|
||||||
$db2->db = $this->db;
|
$db2->db = $this->db;
|
||||||
return $db2;
|
return $db2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ouverture d'une connection vers une database
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $host
|
||||||
|
* @param string $login
|
||||||
|
* @param string $passwd
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
Function pconnect($host, $login, $passwd)
|
Function pconnect($host, $login, $passwd)
|
||||||
{
|
{
|
||||||
$this->db = mysql_pconnect($host, $login, $passwd);
|
$this->db = mysql_pconnect($host, $login, $passwd);
|
||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fermeture d'une connection vers une database
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
Function close()
|
Function close()
|
||||||
{
|
{
|
||||||
return mysql_close($this->db);
|
return mysql_close($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* debut d'un transaction
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $do
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
|
||||||
// Start transaction
|
|
||||||
Function begin($do=1)
|
Function begin($do=1)
|
||||||
{
|
{
|
||||||
if ($do)
|
if ($do)
|
||||||
{
|
{
|
||||||
return $this->query("BEGIN");
|
return $this->query("BEGIN");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit transaction
|
/**
|
||||||
|
* <20>criture d'un transaction
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $do
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
|
||||||
Function commit($do=1)
|
Function commit($do=1)
|
||||||
{
|
{
|
||||||
if ($do)
|
if ($do)
|
||||||
{
|
{
|
||||||
return $this->query("COMMIT");
|
return $this->query("COMMIT");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rollback transaction
|
/**
|
||||||
|
* effacement d'un transaction et retour au ancienne valeurs
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $do
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
|
||||||
Function rollback($do=1)
|
Function rollback($do=1)
|
||||||
{
|
{
|
||||||
if ($do)
|
if ($do)
|
||||||
{
|
{
|
||||||
return $this->query("ROLLBACK");
|
return $this->query("ROLLBACK");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* requete vers une database
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $query
|
||||||
|
* @param string $limit
|
||||||
|
* @param string $offset
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
Function query($query, $limit="", $offset="")
|
Function query($query, $limit="", $offset="")
|
||||||
{
|
{
|
||||||
$query = trim($query);
|
$query = trim($query);
|
||||||
@@ -205,92 +297,204 @@ class DoliDb {
|
|||||||
return $this->results;
|
return $this->results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
*
|
* liste des tables vers une database
|
||||||
*/
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $database
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
Function list_tables($database)
|
Function list_tables($database)
|
||||||
{
|
{
|
||||||
$this->results = mysql_list_tables($database, $this->db);
|
$this->results = mysql_list_tables($database, $this->db);
|
||||||
return $this->results;
|
return $this->results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renvoie les donn<6E>es de la requete
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $nb
|
||||||
|
* @param string $fieldname
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
Function result($nb, $fieldname)
|
Function result($nb, $fieldname)
|
||||||
{
|
{
|
||||||
return mysql_result($this->results, $nb, $fieldname);
|
return mysql_result($this->results, $nb, $fieldname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* d<>salloue la memoire de la requete
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
Function free()
|
Function free()
|
||||||
{
|
{
|
||||||
return mysql_free_result($this->results);
|
return mysql_free_result($this->results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renvoie les donn<6E>es comme un objet
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return resource
|
||||||
|
*/
|
||||||
|
|
||||||
Function fetch_object()
|
Function fetch_object()
|
||||||
{
|
{
|
||||||
return mysql_fetch_object($this->results);
|
return mysql_fetch_object($this->results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* d<>fini les limites de la requ<71>te
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $limit
|
||||||
|
* @param integer $offset
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
|
||||||
Function plimit($limit=0,$offset=0)
|
Function plimit($limit=0,$offset=0)
|
||||||
{
|
{
|
||||||
if ($offset > 0) {
|
if ($offset > 0)
|
||||||
return " LIMIT $offset,$limit ";
|
{
|
||||||
} else {
|
return " LIMIT $offset,$limit ";
|
||||||
return " LIMIT $limit ";
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
return " LIMIT $limit ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Function pdate($fname)
|
Function pdate($fname)
|
||||||
{
|
{
|
||||||
return "unix_timestamp($fname)";
|
return "unix_timestamp($fname)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* formatage de la date en fonction des locales
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $fname
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
|
||||||
Function idate($fname)
|
Function idate($fname)
|
||||||
{
|
{
|
||||||
return strftime("%Y%m%d%H%M%S",$fname);
|
return strftime("%Y%m%d%H%M%S",$fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renvoie les donn<6E>es dans un tableau
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
|
||||||
Function fetch_array()
|
Function fetch_array()
|
||||||
{
|
{
|
||||||
return mysql_fetch_array($this->results);
|
return mysql_fetch_array($this->results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renvoie les donn<6E>es comme un tableau
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
|
||||||
Function fetch_row()
|
Function fetch_row()
|
||||||
{
|
{
|
||||||
return mysql_fetch_row($this->results);
|
return mysql_fetch_row($this->results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get column information from a result and return as an object
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
|
||||||
Function fetch_field()
|
Function fetch_field()
|
||||||
{
|
{
|
||||||
return mysql_fetch_field($this->results);
|
return mysql_fetch_field($this->results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renvoie le nombre de lignes dans le resultat de la requete
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
|
||||||
Function num_rows()
|
Function num_rows()
|
||||||
{
|
{
|
||||||
return mysql_num_rows($this->results);
|
return mysql_num_rows($this->results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renvoie le nombre de champs dans le resultat de la requete
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
|
||||||
Function num_fields()
|
Function num_fields()
|
||||||
{
|
{
|
||||||
return mysql_num_fields($this->results);
|
return mysql_num_fields($this->results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renvoie le texte de l'erreur mysql de l'operation precedente
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
|
||||||
Function error()
|
Function error()
|
||||||
{
|
{
|
||||||
return mysql_error($this->db);
|
return mysql_error($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* renvoie la valeur numerique de l'erreur mysql de l'operation precedente
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
|
||||||
Function errno()
|
Function errno()
|
||||||
{
|
{
|
||||||
// $ERROR_DUPLICATE=1062;
|
// $ERROR_DUPLICATE=1062;
|
||||||
// $ERROR_TABLEEXISTS=1050;
|
// $ERROR_TABLEEXISTS=1050;
|
||||||
|
|
||||||
return mysql_errno($this->db);
|
return mysql_errno($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* obtient l'id gen<65>r<EFBFBD> par le pr<70>cedent INSERT
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
|
||||||
Function last_insert_id()
|
Function last_insert_id()
|
||||||
{
|
{
|
||||||
return mysql_insert_id();
|
return mysql_insert_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* obtient le nombre de lignes affect<63>es dans la pr<70>c<EFBFBD>dente op<6F>ration
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
|
||||||
Function affected_rows()
|
Function affected_rows()
|
||||||
{
|
{
|
||||||
return mysql_affected_rows();
|
return mysql_affected_rows();
|
||||||
|
|||||||
Reference in New Issue
Block a user