aboutsummaryrefslogtreecommitdiffstats
path: root/include/dba/dba_mysqli.php
diff options
context:
space:
mode:
authorHaakon Meland Eriksen <haakon.eriksen@far.no>2014-06-24 19:34:36 +0200
committerHaakon Meland Eriksen <haakon.eriksen@far.no>2014-06-24 19:34:36 +0200
commitb8dc9e855af2d30f33d0f90dc13d8cad0a7b3e70 (patch)
tree718df6305bcb82c8dcb4b287a7132422e748cdfb /include/dba/dba_mysqli.php
parentc2d520f1be115fb3cb5da2a35eb10146cecee8aa (diff)
parenta92fb0b04c3e6474ec48faf8e4cc65c382e89d66 (diff)
downloadvolse-hubzilla-b8dc9e855af2d30f33d0f90dc13d8cad0a7b3e70.tar.gz
volse-hubzilla-b8dc9e855af2d30f33d0f90dc13d8cad0a7b3e70.tar.bz2
volse-hubzilla-b8dc9e855af2d30f33d0f90dc13d8cad0a7b3e70.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'include/dba/dba_mysqli.php')
-rwxr-xr-xinclude/dba/dba_mysqli.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/include/dba/dba_mysqli.php b/include/dba/dba_mysqli.php
new file mode 100755
index 000000000..19907705b
--- /dev/null
+++ b/include/dba/dba_mysqli.php
@@ -0,0 +1,76 @@
+<?php /** @file */
+
+require_once('include/dba/dba_driver.php');
+
+class dba_mysqli extends dba_driver {
+
+ function connect($server, $port, $user,$pass,$db) {
+ if($port)
+ $this->db = new mysqli($server,$user,$pass,$db, $port);
+ else
+ $this->db = new mysqli($server,$user,$pass,$db);
+
+ if(! mysqli_connect_errno()) {
+ $this->connected = true;
+ }
+ if($this->connected) {
+ return true;
+ }
+ $this->error = $this->db->connect_error;
+ return false;
+ }
+
+ 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) {
+ logger('dba_mysqli: ERROR: ' . printable($sql) . "\n" . $this->error);
+ 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) {
+ logger('dba_mysqli: DEBUG: returns ' . (($result) ? 'true' : 'false'));
+ }
+ return $result;
+ }
+
+ if($this->debug) {
+ logger('dba_mysqli: DEBUG: ' . printable($sql) . ' returned ' . $result->num_rows . ' results.');
+ }
+
+ $r = array();
+ if($result->num_rows) {
+ while($x = $result->fetch_array(MYSQLI_ASSOC))
+ $r[] = $x;
+ $result->free_result();
+ if($this->debug) {
+ logger('dba_mysqli: ' . printable(print_r($r,true)));
+ }
+ }
+ 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;
+ }
+
+} \ No newline at end of file