db_addr = $db_addr; $this->db_user = $db_user; $this->db_pass = $db_pass; $this->querycount = 0; if ( $use_pconnect ) { $this->link = @mysql_pconnect($db_addr, $db_user, $db_pass); } else { $this->link = @mysql_connect($db_addr, $db_user, $db_pass); } if ( $this->link ) { $q = @mysql_query("SET NAMES 'utf8'", $this->link); @mysql_free_result($q); if ( $db_name != '' ) { $this->db_name = $db_name; if ( !@mysql_select_db($db_name, $this->link) ) { @mysql_close($this->db_connect_id); $this->error("Could not select database '$db_name'. Check that the value of DB_NAME in config.php is set correctly."); } } return $this->link; } else { $this->error('Could not connect to database server. Check that the values of DB_ADDR, DB_USER and DB_PASS in config.php are set correctly.'); } } function data_seek($row_number, $query_id = 0) { if ( !$query_id ) { $result = $this->last_result; } if ( $query_id ) { return @mysql_data_seek($query_id, $row_number); } return false; } function fetch_array($query_id = 0) { if ( !$query_id ) { $query_id = $this->last_result; } if ( $query_id ) { return @mysql_fetch_array($query_id); } return false; } function fetch_row($query_id = 0) { if ( !$query_id ) { $query_id = $this->last_result; } if ( $query_id ) { return @mysql_fetch_row($query_id); } return false; } function fetch_row_set($query_id = 0) { if ( !$query_id ) { $query_id = $this->last_result; } if ( $query_id ) { $rowset = array(); while ( $row = $this->fetch_array($query_id) ) $rowset[] = $row; return $rowset; } return false; } function free_result($query_id = 0) { if ( !$query_id ) { $query_id = $this->last_result; } if ( $query_id ) { return @mysql_free_result($query_id); } return false; } function insert_id() { return $this->last_insert_id; } function num_rows($query_id = 0) { if ( !$query_id ) { $query_id = $this->last_result; } if ( $query_id ) { return @mysql_num_rows($query_id); } return false; } function calc_rows() { return $this->last_calc_rows; } function query($query, $showerror=true, $calcrows=false) { $this->last_query = $query; $starttime = microtime(true); if($calcrows == true) { /* Add sql_calc_found_rows to this query */ $query = preg_replace('/select/i', 'select sql_calc_found_rows', $query, 1); } $this->last_result = @mysql_query($query, $this->link); $endtime = microtime(true); $this->last_insert_id = @mysql_insert_id($this->link); if($calcrows == true) { $calc_result = @mysql_query("select found_rows() as rowcount"); if($row = mysql_fetch_assoc($calc_result)) { $this->last_calc_rows = $row['rowcount']; } } $this->querycount++; if ( defined('DB_DEBUG') && DB_DEBUG == true ) { echo "
$query
$this->last_query", $exit ); } } ?>