Go to the documentation of this file.
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;
82 return (empty($this->prefix_db) ? MAIN_DB_PREFIX : $this->prefix_db);
93 public function ifsql($test, $resok, $resko)
96 return '(CASE WHEN '.$test.
' THEN '.$resok.
' ELSE '.$resko.
' END)';
118 public function idate($param, $gm =
'tzserver')
131 return $this->lasterrno;
141 public function sanitize($stringtosanitize, $allowsimplequote = 0)
143 if ($allowsimplequote) {
144 return preg_replace(
'/[^a-z0-9_\-\.,\']/i',
'', $stringtosanitize);
146 return preg_replace(
'/[^a-z0-9_\-\.,]/i',
'', $stringtosanitize);
157 if (!$this->transaction_opened) {
158 $ret = $this->
query(
"BEGIN");
160 $this->transaction_opened++;
166 $this->transaction_opened++;
181 if ($this->transaction_opened <= 1) {
182 $ret = $this->
query(
"COMMIT");
184 $this->transaction_opened = 0;
185 dol_syslog(
"COMMIT Transaction".($log ?
' '.$log :
''), LOG_DEBUG);
191 $this->transaction_opened--;
205 if ($this->transaction_opened <= 1) {
206 $ret = $this->
query(
"ROLLBACK");
207 $this->transaction_opened = 0;
208 dol_syslog(
"ROLLBACK Transaction".($log ?
' '.$log :
''), LOG_DEBUG);
211 $this->transaction_opened--;
223 public function plimit($limit = 0, $offset = 0)
230 $limit = $conf->liste_limit;
233 return " LIMIT ".((int) $offset).
",".((int) $limit).
" ";
235 return " LIMIT ".((int) $limit).
" ";
246 return preg_split(
"/[\.,-]/", $this->
getVersion());
256 return $this->lastquery;
266 public function order($sortfield =
null, $sortorder =
null)
268 if (!empty($sortfield)) {
271 $fields = explode(
',', $sortfield);
272 $orders = explode(
',', $sortorder);
274 foreach ($fields as $val) {
276 $return .=
' ORDER BY ';
281 $return .= preg_replace(
'/[^0-9a-z_\.]/i',
'', $val);
283 $tmpsortorder = (empty($orders[$i]) ?
'' : trim($orders[$i]));
286 if (strtoupper($tmpsortorder) ===
'ASC') {
287 $oldsortorder =
'ASC';
289 } elseif (strtoupper($tmpsortorder) ===
'DESC') {
290 $oldsortorder =
'DESC';
293 $return .=
' '.($oldsortorder ? $oldsortorder :
'ASC');
311 return $this->lasterror;
323 public function jdate($string, $gm =
'tzserver')
326 if ($string == 0 || $string ==
"0000-00-00 00:00:00") {
329 $string = preg_replace(
'/([^0-9])/i',
'', $string);
330 $tmp = $string.
'000000';
331 $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);
342 return $this->lastqueryerror;
357 $res = $this->
query($sql);
381 $res = $this->
query($sql);
prefix()
Return the DB prefix.
commit($log='')
Validate a database transaction.
lasterror()
Return last error label.
getVersion()
Return version of database server.
Class to manage Dolibarr database access.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
lastquery()
Return last request executed with query()
rollback($log='')
Cancel a transaction and go back to initial data values.
hintindex($nameofindex)
Return SQL string to force an index.
ifsql($test, $resok, $resko)
Format a SQL IF.
fetch_object($resultset)
Returns the current line (as an object) for the resultset cursor.
lasterrno()
Return last error code.
getVersionArray()
Return version of database server into an array.
getRow($sql)
Return first result from query as object Note : This method executes a given SQL query and retrieves ...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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...
order($sortfield=null, $sortorder=null)
Define sort criteria of request.
lastqueryerror()
Return last query in error.
Class to manage Dolibarr database access for an SQL database.
begin()
Start transaction.
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.
num_rows($resultset)
Return number of lines for result of a SELECT.
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
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...
getRows($sql)
Return all results from query as an array of objects Note : This method executes a given SQL query an...
sanitize($stringtosanitize, $allowsimplequote=0)
Sanitize a string for SQL forging.