diff --git a/lib/db.class.php b/lib/db.class.php index fea3373..1b5e6c6 100644 --- a/lib/db.class.php +++ b/lib/db.class.php @@ -18,11 +18,11 @@ public function __construct( $host, $db, $user, $pass) { private function connect() { - $this->link = @mysql_connect( $this->host, $this->user, $this->pass ) + $this->link = mysqli_connect( $this->host, $this->user, $this->pass ) or die( "Couldn't establish link to database-server: ".$this->host ); - mysql_select_db( $this->db ) + mysqli_select_db( $this->db ) or die( "Couldn't select Database: ".$this->db ); - mysql_query( 'SET NAMES utf8', $this->link ); + mysqli_query( 'SET NAMES utf8', $this->link ); } @@ -33,17 +33,17 @@ public function foundRows() { public function numRows() { - return mysql_num_rows( $this->result ); + return mysqli_num_rows( $this->result ); } public function affectedRows() { - return mysql_affected_rows( $this->result ); + return mysqli_affected_rows( $this->result ); } public function insertId() { - return mysql_insert_id( $this->link ); + return mysqli_insert_id( $this->link ); } @@ -57,21 +57,25 @@ public function query( $q, $params = array() ) { } if( !empty( $params ) ) { - $q = preg_replace('/:(\d+)/e', '$this->quote($params[$1 - 1])', $q ); + $q = preg_replace_callback('/:(\d+)/', + function($repl) use ($params){ + return $this->quote($params[$repl[1] - 1]); + }, + $q); } $this->numQueries++; $this->sql = $q; - $this->result = mysql_query( $q, $this->link ); + $this->result = mysqli_query( $q, $this->link ); if( !$this->result ) { return false; } - else if( !is_resource( $this->result ) ) { + else if( !( $this->result instanceof mysqli_result ) ) { return true; } $rset = array(); - while ( $row = mysql_fetch_assoc( $this->result ) ) { + while ( $row = mysqli_fetch_assoc( $this->result ) ) { $rset[] = $row; } return $rset; @@ -123,7 +127,7 @@ public function quote( $s ) { return $s; } else { - return "'".mysql_real_escape_string( $s )."'"; + return "'".mysqli_real_escape_string( $this->link, $s )."'"; } } @@ -137,4 +141,4 @@ public function quoteArray( &$fields ) { } } -?> \ No newline at end of file +?>