Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions lib/db.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand All @@ -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 );
}


Expand All @@ -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;
Expand Down Expand Up @@ -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 )."'";
}
}

Expand All @@ -137,4 +141,4 @@ public function quoteArray( &$fields ) {
}
}

?>
?>