*/ class HydraSQL { var $resid; var $errormsg; var $config = array; var $messages = array( 0 => 'Não foi possível conectar ao banco de dados', 1 => 'Não foi possível selecionar o banco de dados' ); function HidraSQL($host, $port, $user, $pass, $db, $type) { $this->config['host'] = $host; $this->config['port'] = $port; $this->config['user'] = $user; $this->config['pass'] = $pass; $this->config['db'] = $db; $this->config['type'] = strtolower($type); } function connect() { switch($this->config['type']) { case 'mysql': $id = @mysql_connect($this->config['host'].$this->config['port'], $this->config['user'], $this->config['pass']) or $this->_error($this->messages[0]); @mysql_select_db($this->config['db']) or $this->_error($this->messages[1]); break; case 'postgresql': $id = @pg_connect('host='.$this->config['host'].' port='.$this->config['port'].' dbname='.$this->config['db'].' user='.$this->config['user'].' password='.$this->config['pass']) or $this->_error($this->messages[0]); break; } $this->resid = $id; return $id; } function query($query) { switch($this->config['type']) { case 'mysql': $id = @mysql_query($query, $this->resid) or $this->_error($this->_bderror()); break; case 'postgresql': $id = @pg_exec($this->resid, $query) or $this->_error($this->_bderror()); break; } return $id; } function fetch_row($id) { switch($this->config['type']) { case 'mysql': $row = mysql_fetch_row($id); break; case 'postgresql': $row = pg_fetch_row($id); break; } return $row; } function fetch_array($id) { switch($this->config['type']) { case 'mysql': $row = mysql_fetch_array($id); break; case 'postgresql': $row = pg_fetch_array($id); break; } return $row; } function num_rows($id) { switch($this->config['type']) { case 'mysql': $num = mysql_num_rows($id); break; case 'postgresql': $num = pg_numrows($id); break; } return $num; } function _error($msg) { $this->errormsg = $msg; return 0; } function _bderror() { switch($this->config['type']) { case 'mysql': $msg = mysql_error($this->resid); break; case 'postgresql': $msg = pg_errormessage($this->resid); break; } return $msg; } } ?>