Page principale | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de classe | Membres de fichier

htdocs/lib/mysql.lib.php

Aller à la documentation de ce fichier.
00001 <?PHP 00002 /* Copyright (C) 2001 Fabien Seisen <seisen@linuxfr.org> 00003 * Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> 00004 * Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> 00005 * 00006 * $Id$ 00007 * $Source$ 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 * 00023 */ 00024 00041 class DoliDb { 00042 var $db, $results, $ok, $connected, $database_selected; 00043 00044 // Constantes pour code erreurs 00045 var $ERROR_DUPLICATE=1062; 00046 var $ERROR_TABLEEXISTS=1050; 00047 00057 function DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '') 00058 00059 // Se connecte au serveur et éventuellement à une base (si spécifié) 00060 // Renvoie 1 en cas de succès, 0 sinon 00061 00062 { 00063 global $conf; 00064 00065 if ($host == '') 00066 { 00067 $host = $conf->db->host; 00068 } 00069 00070 if ($user == '') 00071 { 00072 $user = $conf->db->user; 00073 } 00074 00075 if ($pass == '') 00076 { 00077 $pass = $conf->db->pass; 00078 } 00079 00080 if ($name == '') 00081 { 00082 $name = $conf->db->name; 00083 } 00084 00085 //print "Name DB: $host,$user,$pass,$name<br>"; 00086 00087 // Essai connexion serveur 00088 00089 $this->db = $this->connect($host, $user, $pass); 00090 00091 if ($this->db) 00092 { 00093 $this->connected = 1; 00094 $this->ok = 1; 00095 } 00096 else 00097 { 00098 $this->connected = 0; 00099 $this->ok = 0; 00100 } 00101 00102 // Si connexion serveur ok et si connexion base demandée, on essaie connexion base 00103 00104 if ($this->connected && $name) 00105 { 00106 00107 if ($this->select_db($name) == 1) 00108 { 00109 $this->database_selected = 1; 00110 $this->ok = 1; 00111 } 00112 else 00113 { 00114 $this->database_selected = 0; 00115 $this->ok = 0; 00116 } 00117 00118 } 00119 else 00120 { 00121 // Pas de selection de base demandée, mais tout est ok 00122 00123 $this->database_selected = 0; 00124 $this->ok = 1; 00125 } 00126 00127 return $this->ok; 00128 } 00129 00136 function select_db($database) 00137 { 00138 return mysql_select_db($database, $this->db); 00139 } 00140 00149 function connect($host, $login, $passwd) 00150 { 00151 $this->db = @mysql_connect($host, $login, $passwd); 00152 //print "Resultat fonction connect: ".$this->db; 00153 return $this->db; 00154 } 00155 00162 function create_db($database) 00163 { 00164 if (mysql_create_db ($database, $this->db)) 00165 { 00166 return 1; 00167 } 00168 else 00169 { 00170 return 0; 00171 } 00172 } 00173 00179 function clone() 00180 { 00181 $db2 = new DoliDb("", "", "", "", ""); 00182 $db2->db = $this->db; 00183 return $db2; 00184 } 00185 00194 function pconnect($host, $login, $passwd) 00195 { 00196 $this->db = mysql_pconnect($host, $login, $passwd); 00197 return $this->db; 00198 } 00199 00205 function close() 00206 { 00207 return mysql_close($this->db); 00208 } 00209 00216 function begin($do=1) 00217 { 00218 if ($do) 00219 { 00220 return $this->query("BEGIN"); 00221 } 00222 else 00223 { 00224 return 1; 00225 } 00226 } 00227 00234 function commit($do=1) 00235 { 00236 if ($do) 00237 { 00238 return $this->query("COMMIT"); 00239 } 00240 else 00241 { 00242 return 1; 00243 } 00244 } 00245 00252 function rollback($do=1) 00253 { 00254 if ($do) 00255 { 00256 return $this->query("ROLLBACK"); 00257 } 00258 else 00259 { 00260 return 1; 00261 } 00262 } 00263 00272 function query($query, $limit="", $offset="") 00273 { 00274 $query = trim($query); 00275 //print "<p>$query</p>\n"; 00276 $this->results = mysql_query($query, $this->db); 00277 return $this->results; 00278 } 00279 00286 function list_tables($database) 00287 { 00288 $this->results = mysql_list_tables($database, $this->db); 00289 return $this->results; 00290 } 00291 00299 function result($nb, $fieldname) 00300 { 00301 return mysql_result($this->results, $nb, $fieldname); 00302 } 00303 00309 function free() 00310 { 00311 return mysql_free_result($this->results); 00312 } 00313 00319 function fetch_object() 00320 { 00321 return mysql_fetch_object($this->results); 00322 } 00323 00331 function plimit($limit=0,$offset=0) 00332 { 00333 if ($offset > 0) 00334 { 00335 return " LIMIT $offset,$limit "; 00336 } 00337 else 00338 { 00339 return " LIMIT $limit "; 00340 } 00341 } 00342 00343 00344 function pdate($fname) 00345 { 00346 return "unix_timestamp($fname)"; 00347 } 00348 00355 function idate($fname) 00356 { 00357 return strftime("%Y%m%d%H%M%S",$fname); 00358 } 00359 00365 function fetch_array() 00366 { 00367 return mysql_fetch_array($this->results); 00368 } 00369 00375 function fetch_row() 00376 { 00377 return mysql_fetch_row($this->results); 00378 } 00379 00384 function fetch_field() 00385 { 00386 return mysql_fetch_field($this->results); 00387 } 00388 00389 00395 function num_rows() 00396 { 00397 return mysql_num_rows($this->results); 00398 } 00399 00405 function num_fields() 00406 { 00407 return mysql_num_fields($this->results); 00408 } 00409 00415 function error() 00416 { 00417 return mysql_error($this->db); 00418 } 00419 00425 function errno() 00426 { 00427 // $ERROR_DUPLICATE=1062; 00428 // $ERROR_TABLEEXISTS=1050; 00429 00430 return mysql_errno($this->db); 00431 } 00432 00438 function last_insert_id() 00439 { 00440 return mysql_insert_id(); 00441 } 00442 00448 function affected_rows() 00449 { 00450 return mysql_affected_rows(); 00451 } 00452 00453 } 00454 00455 ?>

Généré le Fri Jul 16 00:31:07 2004 pour dolibarr par doxygen 1.3.7