aboutsummaryrefslogtreecommitdiffstats
path: root/include/dba/dba_mysqli.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-04-22 20:02:21 -0700
committerfriendica <info@friendica.com>2013-04-22 20:02:21 -0700
commit552f03122c9ec066f5728fc4629d155937fd3620 (patch)
tree1e8a585b52fa28d1c47abd70d89bb1225fe99eb7 /include/dba/dba_mysqli.php
parent7621bd3bb171c7a4772e4663ee43b86a55a1f7c0 (diff)
downloadvolse-hubzilla-552f03122c9ec066f5728fc4629d155937fd3620.tar.gz
volse-hubzilla-552f03122c9ec066f5728fc4629d155937fd3620.tar.bz2
volse-hubzilla-552f03122c9ec066f5728fc4629d155937fd3620.zip
db abstraction layer
Diffstat (limited to 'include/dba/dba_mysqli.php')
-rw-r--r--include/dba/dba_mysqli.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/include/dba/dba_mysqli.php b/include/dba/dba_mysqli.php
new file mode 100644
index 000000000..10a0a05c2
--- /dev/null
+++ b/include/dba/dba_mysqli.php
@@ -0,0 +1,62 @@
+<?php /** @file */
+
+require_once('include/dba/dba_driver.php');
+
+class dba_mysqli extends dba_driver {
+
+ 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;
+ }
+
+ 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: query: ' . printable($sql) . ' returned ' . $result->num_rows . ' results.');
+ 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 = flase;
+ }
+
+} \ No newline at end of file