25 require_once DOL_DOCUMENT_ROOT.
'/core/db/Database.interface.php';
37 public $forcecharset =
'utf8';
39 public $forcecollate =
'utf8_unicode_ci';
45 public $database_selected;
47 public $database_name;
49 public $database_user;
51 public $database_host;
53 public $database_port;
55 public $transaction_opened;
59 public $lastqueryerror;
78 public function ifsql($test, $resok, $resko)
80 return 'IF('.$test.
','.$resok.
','.$resko.
')';
91 public function idate($param, $gm =
'tzserver')
104 return $this->lasterrno;
114 public function sanitize($stringtosanitize, $allowsimplequote = 0)
116 if ($allowsimplequote) {
117 return preg_replace(
'/[^a-z0-9_\-\.,\']/i',
'', $stringtosanitize);
119 return preg_replace(
'/[^a-z0-9_\-\.,]/i',
'', $stringtosanitize);
130 if (!$this->transaction_opened)
132 $ret = $this->
query(
"BEGIN");
135 $this->transaction_opened++;
141 $this->transaction_opened++;
156 if ($this->transaction_opened <= 1)
158 $ret = $this->
query(
"COMMIT");
161 $this->transaction_opened = 0;
162 dol_syslog(
"COMMIT Transaction".($log ?
' '.$log :
''), LOG_DEBUG);
168 $this->transaction_opened--;
182 if ($this->transaction_opened <= 1)
184 $ret = $this->
query(
"ROLLBACK");
185 $this->transaction_opened = 0;
186 dol_syslog(
"ROLLBACK Transaction".($log ?
' '.$log :
''), LOG_DEBUG);
189 $this->transaction_opened--;
201 public function plimit($limit = 0, $offset = 0)
204 if (empty($limit))
return "";
205 if ($limit < 0) $limit = $conf->liste_limit;
206 if ($offset > 0)
return " LIMIT $offset,$limit ";
207 else return " LIMIT $limit ";
217 return preg_split(
"/[\.,-]/", $this->
getVersion());
227 return $this->lastquery;
237 public function order($sortfield = null, $sortorder = null)
239 if (!empty($sortfield))
243 $fields = explode(
',', $sortfield);
244 $orders = explode(
',', $sortorder);
246 foreach ($fields as $val) {
247 if (!$return) $return .=
' ORDER BY ';
248 else $return .=
', ';
250 $return .= preg_replace(
'/[^0-9a-z_\.]/i',
'', $val);
252 $tmpsortorder = (empty($orders[$i]) ?
'' : trim($orders[$i]));
255 if (strtoupper($tmpsortorder) ===
'ASC') {
256 $oldsortorder =
'ASC';
258 } elseif (strtoupper($tmpsortorder) ===
'DESC') {
259 $oldsortorder =
'DESC';
262 $return .=
' '.($oldsortorder ? $oldsortorder :
'ASC');
280 return $this->lasterror;
292 public function jdate($string, $gm =
'tzserver')
295 if ($string == 0 || $string ==
"0000-00-00 00:00:00")
return '';
296 $string = preg_replace(
'/([^0-9])/i',
'', $string);
297 $tmp = $string.
'000000';
298 $date =
dol_mktime((
int) substr($tmp, 8, 2), (
int) substr($tmp, 10, 2), (
int) substr($tmp, 12, 2), (
int) substr($tmp, 4, 2), (
int) substr($tmp, 6, 2), (
int) substr($tmp, 0, 4), $gm);
309 return $this->lastqueryerror;
323 $res = $this->
query($sql);
341 $res = $this->
query($sql);
getRow($sql)
Return first result from query as object Note : This method executes a given SQL query and retrieves ...
Class to manage Dolibarr database access for an SQL database.
lastqueryerror()
Return last query in error.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
lastquery()
Return last request executed with query()
Class to manage Dolibarr database access.
ifsql($test, $resok, $resko)
Format a SQL IF.
lasterror()
Return last error label.
fetch_object($resultset)
Returns the current line (as an object) for the resultset cursor.
begin()
Start transaction.
num_rows($resultset)
Return number of lines for result of a SELECT.
getRows($sql)
return all results from query as an array of objects Note : This method executes a given SQL query an...
commit($log= '')
Validate a database transaction.
query($query, $usesavepoint=0, $type= 'auto')
Execute a SQL request and return the resultset.
sanitize($stringtosanitize, $allowsimplequote=0)
Sanitize a string for SQL forging.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getVersion()
Return version of database server.
jdate($string, $gm= 'tzserver')
Convert (by PHP) a PHP server TZ string date into a Timestamps date (GMT if gm=true) 19700101020000 -...
plimit($limit=0, $offset=0)
Define limits and offset of request.
getVersionArray()
Return version of database server into an array.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
lasterrno()
Return last error code.
order($sortfield=null, $sortorder=null)
Define sort criteria of request.
rollback($log= '')
Cancel a transaction and go back to initial data values.
idate($param, $gm= 'tzserver')
Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date fiel...