00001 <?PHP
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00041 class DoliDb {
00042 var $db, $results, $ok, $connected, $database_selected;
00043
00044
00045 var $ERROR_DUPLICATE=1062;
00046 var $ERROR_TABLEEXISTS=1050;
00047
00057 function
DoliDb($type = 'mysql', $host = '', $user = '', $pass = '', $name = '')
00058
00059
00060
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
00086
00087
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
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
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
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
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
00428
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 ?>