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 00035 class DoliDb { 00036 var $db, $results, $ok, $connected, $database_selected; 00037 00038 // Constantes pour code erreurs 00039 var $ERROR_DUPLICATE=1062; 00040 var $ERROR_TABLEEXISTS=1050; 00041 00051 Function DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '') 00052 00053 // Se connecte au serveur et éventuellement à une base (si spécifié) 00054 // Renvoie 1 en cas de succès, 0 sinon 00055 00056 { 00057 global $conf; 00058 00059 if ($host == '') 00060 { 00061 $host = $conf->db->host; 00062 } 00063 00064 if ($user == '') 00065 { 00066 $user = $conf->db->user; 00067 } 00068 00069 if ($pass == '') 00070 { 00071 $pass = $conf->db->pass; 00072 } 00073 00074 if ($name == '') 00075 { 00076 $name = $conf->db->name; 00077 } 00078 00079 //print "Name DB: $host,$user,$pass,$name<br>"; 00080 00081 // Essai connexion serveur 00082 00083 $this->db = $this->connect($host, $user, $pass); 00084 00085 if ($this->db) 00086 { 00087 $this->connected = 1; 00088 $this->ok = 1; 00089 } 00090 else 00091 { 00092 $this->connected = 0; 00093 $this->ok = 0; 00094 } 00095 00096 // Si connexion serveur ok et si connexion base demandée, on essaie connexion base 00097 00098 if ($this->connected && $name) 00099 { 00100 00101 if ($this->select_db($name) == 1) 00102 { 00103 $this->database_selected = 1; 00104 $this->ok = 1; 00105 } 00106 else 00107 { 00108 $this->database_selected = 0; 00109 $this->ok = 0; 00110 } 00111 00112 } 00113 else 00114 { 00115 // Pas de selection de base demandée, mais tout est ok 00116 00117 $this->database_selected = 0; 00118 $this->ok = 1; 00119 } 00120 00121 return $this->ok; 00122 } 00123 00130 Function select_db($database) 00131 { 00132 return mysql_select_db($database, $this->db); 00133 } 00134 00143 Function connect($host, $login, $passwd) 00144 { 00145 $this->db = @mysql_connect($host, $login, $passwd); 00146 //print "Resultat fonction connect: ".$this->db; 00147 return $this->db; 00148 } 00149 00156 Function create_db($database) 00157 { 00158 if (mysql_create_db ($database, $this->db)) 00159 { 00160 return 1; 00161 } 00162 else 00163 { 00164 return 0; 00165 } 00166 } 00167 00173 Function clone() 00174 { 00175 $db2 = new DoliDb("", "", "", "", ""); 00176 $db2->db = $this->db; 00177 return $db2; 00178 } 00179 00188 Function pconnect($host, $login, $passwd) 00189 { 00190 $this->db = mysql_pconnect($host, $login, $passwd); 00191 return $this->db; 00192 } 00193 00199 Function close() 00200 { 00201 return mysql_close($this->db); 00202 } 00203 00210 Function begin($do=1) 00211 { 00212 if ($do) 00213 { 00214 return $this->query("BEGIN"); 00215 } 00216 else 00217 { 00218 return 1; 00219 } 00220 } 00221 00228 Function commit($do=1) 00229 { 00230 if ($do) 00231 { 00232 return $this->query("COMMIT"); 00233 } 00234 else 00235 { 00236 return 1; 00237 } 00238 } 00239 00246 Function rollback($do=1) 00247 { 00248 if ($do) 00249 { 00250 return $this->query("ROLLBACK"); 00251 } 00252 else 00253 { 00254 return 1; 00255 } 00256 } 00257 00266 Function query($query, $limit="", $offset="") 00267 { 00268 $query = trim($query); 00269 //print "<p>$query</p>\n"; 00270 $this->results = mysql_query($query, $this->db); 00271 return $this->results; 00272 } 00273 00280 Function list_tables($database) 00281 { 00282 $this->results = mysql_list_tables($database, $this->db); 00283 return $this->results; 00284 } 00285 00293 Function result($nb, $fieldname) 00294 { 00295 return mysql_result($this->results, $nb, $fieldname); 00296 } 00297 00303 Function free() 00304 { 00305 return mysql_free_result($this->results); 00306 } 00307 00313 Function fetch_object() 00314 { 00315 return mysql_fetch_object($this->results); 00316 } 00317 00325 Function plimit($limit=0,$offset=0) 00326 { 00327 if ($offset > 0) 00328 { 00329 return " LIMIT $offset,$limit "; 00330 } 00331 else 00332 { 00333 return " LIMIT $limit "; 00334 } 00335 } 00336 00337 00338 Function pdate($fname) 00339 { 00340 return "unix_timestamp($fname)"; 00341 } 00342 00349 Function idate($fname) 00350 { 00351 return strftime("%Y%m%d%H%M%S",$fname); 00352 } 00353 00359 Function fetch_array() 00360 { 00361 return mysql_fetch_array($this->results); 00362 } 00363 00369 Function fetch_row() 00370 { 00371 return mysql_fetch_row($this->results); 00372 } 00373 00381 Function fetch_field() 00382 { 00383 return mysql_fetch_field($this->results); 00384 } 00385 00386 00392 Function num_rows() 00393 { 00394 return mysql_num_rows($this->results); 00395 } 00396 00402 Function num_fields() 00403 { 00404 return mysql_num_fields($this->results); 00405 } 00406 00412 Function error() 00413 { 00414 return mysql_error($this->db); 00415 } 00416 00422 Function errno() 00423 { 00424 // $ERROR_DUPLICATE=1062; 00425 // $ERROR_TABLEEXISTS=1050; 00426 00427 return mysql_errno($this->db); 00428 } 00429 00435 Function last_insert_id() 00436 { 00437 return mysql_insert_id(); 00438 } 00439 00445 Function affected_rows() 00446 { 00447 return mysql_affected_rows(); 00448 } 00449 00450 } 00451 00452 ?>

Généré le Thu Jul 15 20:50:38 2004 pour dolibarr par doxygen 1.3.7