db_host = $str_host; $this->db_port = $int_port; $this->db_socket = $str_socket; $this->db_name = $str_dbname; $this->db_username = $str_username; $this->db_passwd = $str_passwd; // execute connection $this->connect(); } /** * Method to invoke connection to RDBMS * * @return void */ private function connect() { if ($this->db_socket) { $this->res_conn = @mysql_connect($this->db_host.":".$this->db_socket, $this->db_username, $this->db_passwd); } else { $this->res_conn = @mysql_connect($this->db_host.":".$this->db_port, $this->db_username, $this->db_passwd); } // check the connection status if (!$this->res_conn) { $this->error = 'Error Connecting to Database. Please check your configuration'; parent::showError(true); } else { // select the database $db = @mysql_select_db($this->db_name, $this->res_conn); if (!$db) { $this->error = 'Error Opening Database'; parent::showError(true); } } } /** * Method to create/send query to RDBMS * * @param string $str_query * @return object */ public function query($str_query = '') { if (empty($str_query)) { $this->error = "Error on simbio_mysql::query() method : query empty"; parent::showError(true); } else { // create simbio_mysql_result object $result = new simbio_mysql_result($str_query, $this->res_conn); // get any properties from result object $this->affected_rows = $result->affected_rows; $this->errno = $result->errno; $this->error = $result->error; $this->insert_id = $result->insert_id; // return the result object if ($this->error) { return false; } else { return $result; } } } /** * Method to escape SQL string * * @param string $str_data * @return string */ public function escape_string($str_data) { return mysql_real_escape_string($str_data, $this->res_conn); } /** * Method to close RDBMS connection * * @return void */ public function close() { mysql_close($this->res_conn); } } ?>