2015-08-23 22:38:18 +02:00
|
|
|
<?php /** @file */
|
|
|
|
|
|
|
|
require_once('include/dba/dba_driver.php');
|
|
|
|
|
|
|
|
class dba_mysqli extends dba_driver {
|
|
|
|
|
2016-05-17 19:05:14 +02:00
|
|
|
function connect($server,$port,$user,$pass,$db) {
|
2015-08-23 22:38:18 +02:00
|
|
|
if($port)
|
|
|
|
$this->db = new mysqli($server,$user,$pass,$db, $port);
|
|
|
|
else
|
|
|
|
$this->db = new mysqli($server,$user,$pass,$db);
|
|
|
|
|
2016-05-17 19:05:14 +02:00
|
|
|
if($this->db->connect_error) {
|
|
|
|
$this->connected = false;
|
|
|
|
$this->error = $this->db->connect_error;
|
|
|
|
|
|
|
|
if(file_exists('dbfail.out')) {
|
|
|
|
file_put_contents('dbfail.out', datetime_convert() . "\nConnect: " . $this->error . "\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-08-23 22:38:18 +02:00
|
|
|
}
|
2016-05-17 19:05:14 +02:00
|
|
|
else {
|
|
|
|
$this->connected = true;
|
2015-08-23 22:38:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function q($sql) {
|
|
|
|
if((! $this->db) || (! $this->connected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$this->error = '';
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
if($this->db->errno)
|
|
|
|
$this->error = $this->db->error;
|
|
|
|
|
|
|
|
|
|
|
|
if($this->error) {
|
2016-05-17 19:05:14 +02:00
|
|
|
db_logger('dba_mysqli: ERROR: ' . printable($sql) . "\n" . $this->error, LOGGER_NORMAL, LOG_ERR);
|
2015-08-23 22:38:18 +02:00
|
|
|
if(file_exists('dbfail.out')) {
|
|
|
|
file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(($result === true) || ($result === false)) {
|
|
|
|
if($this->debug) {
|
2016-05-17 19:05:14 +02:00
|
|
|
db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returns ' . (($result) ? 'true' : 'false'), LOGGER_NORMAL,(($result) ? LOG_INFO : LOG_ERR));
|
2015-08-23 22:38:18 +02:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($this->debug) {
|
2016-05-17 19:05:14 +02:00
|
|
|
db_logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returned ' . $result->num_rows . ' results.', LOGGER_NORMAL, LOG_INFO);
|
2015-08-23 22:38:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$r = array();
|
|
|
|
if($result->num_rows) {
|
|
|
|
while($x = $result->fetch_array(MYSQLI_ASSOC))
|
|
|
|
$r[] = $x;
|
|
|
|
$result->free_result();
|
|
|
|
if($this->debug) {
|
2016-05-17 19:05:14 +02:00
|
|
|
db_logger('dba_mysqli: ' . printable(print_r($r,true)), LOGGER_NORMAL, LOG_INFO);
|
2015-08-23 22:38:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
function escape($str) {
|
|
|
|
if($this->db && $this->connected) {
|
|
|
|
return @$this->db->real_escape_string($str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
if($this->db)
|
|
|
|
$this->db->close();
|
|
|
|
$this->connected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getdriver() {
|
|
|
|
return 'mysqli';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|