diff options
author | friendica <info@friendica.com> | 2013-04-17 01:47:36 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-04-17 01:47:36 -0700 |
commit | 3e1b005de0ba5e596296aed9900c44a8c3116565 (patch) | |
tree | f98bc54928faa4b07bba8ddaa2cf3ab8e88572f1 /include/dba_mysqli.php | |
parent | 23f897b8aedac8a99aa81ac7799ec67ca196d407 (diff) | |
download | volse-hubzilla-3e1b005de0ba5e596296aed9900c44a8c3116565.tar.gz volse-hubzilla-3e1b005de0ba5e596296aed9900c44a8c3116565.tar.bz2 volse-hubzilla-3e1b005de0ba5e596296aed9900c44a8c3116565.zip |
start of DB driver abstraction class (we'll need similar mechanisms for the GD/ImageMagick photo stuff and perhaps also for abstracting alternate "social networks")
Diffstat (limited to 'include/dba_mysqli.php')
-rw-r--r-- | include/dba_mysqli.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/include/dba_mysqli.php b/include/dba_mysqli.php new file mode 100644 index 000000000..24b8aad6e --- /dev/null +++ b/include/dba_mysqli.php @@ -0,0 +1,60 @@ +<?php /** @file */ + +require_once('include/dba_driver.php'); + +abstract class dba_mysqli extends dba_driver { + + protected function connect($server,$user,$pass,$db) { + $this->db = @new mysqli($server,$user,$pass,$db); + if(! mysqli_connect_errno()) { + $this->connected = true; + } + if($this->connected) { + return true; + } + return false; + } + + protected 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($result === false || $this->error) { + logger('dba_mysqli: ' . printable($sql) . ' returned false.' . "\n" . $this->error); + if(file_exists('dbfail.out')) + file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); + } + + if(($result === true) || ($result === false)) + return $result; + + $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; + } + + protected function escape($str) { + if($this->db && $this->connected) { + return @$this->db->real_escape_string($str); + } + } + + protected function close() { + if($this->db) + $this->db->close(); + $this->connected = flase; + } + +}
\ No newline at end of file |