sql_string = trim($str_query); $this->sendQuery($res_conn); } /** * Method to send SQL query * * @param resource $res_conn * @return void */ private function sendQuery($res_conn) { // checking query type // if the query return recordset or not if (preg_match("/^SELECT|DESCRIBE|SHOW|EXPLAIN\s/i", $this->sql_string)) { $this->res_result = @mysql_query($this->sql_string, $res_conn); // error checking if (!$this->res_result) { $this->error = 'Query ('.$this->sql_string.") failed to executed. Please check your query again \n".mysql_error($res_conn); $this->errno = mysql_errno($res_conn); } else { // count number of rows $this->num_rows = @mysql_num_rows($this->res_result); $this->field_count = @mysql_num_fields($this->res_result); } } else { $query = @mysql_query($this->sql_string, $res_conn); $this->insert_id = @mysql_insert_id($res_conn); // error checking if (!$query) { $this->error = 'Query ('.$this->sql_string.") failed to executed. Please check your query again \n".mysql_error($res_conn); $this->errno = mysql_errno($res_conn); } else { // get number of affected row $this->affected_rows = @mysql_affected_rows($res_conn); } // nullify query $query = null; } } /** * Method to fetch record in associative array * * @return array */ public function fetch_assoc() { return @mysql_fetch_assoc($this->res_result); } /** * Method to fetch record in numeric array indexes * * @return array */ public function fetch_row() { return @mysql_fetch_row($this->res_result); } /** * Method to fetch fields information of resultset * * @return array */ public function fetch_fields() { $_fields_info = array(); $_f = 0; $_field_num = mysql_num_fields($this->res_result); while ($_f < $_field_num) { $_fields_info[] = mysql_fetch_field($this->res_result, $_f); $_f++; } return $_fields_info; } /** * Method to free resultset memory * * @return void */ public function free_result() { if ($this->res_result) { @mysql_free_result($this->res_result); } } } ?>