<?
class mydb{
var $debug=0;
var $host="teste.com.br";
var $user="username";
var $pass="passwrod";
var $database="tablename";
var $error;
var $msgerror;
var $ConId=NULL;
var $recordcount=-1;
var $MESSAGE["CONNECTIG"] = "Conectando...";
var $MESSAGE["CONNECTED"] = "Conectado.";
var $MESSAGE["CONECTIONERROR"] = "Erro ao estabelecer a conexão com o Servidor";
var $MESSAGE["DATABASEERROR"] = "Erro ao selecionar o database";
var $MESSAGE["COMMANDERROR"] = "Erro no comando : ";
var $MESSAGE["QUERYERROR"] = "Erro na consulta : ";
function GafDb( $host , $user , $pass , $database ){
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->database = $database;
if ($this->debug<>0) echo $MESSAGE["CONNECTIG"]; // debug
$con=mysql_connect($this->host ,$this->user ,$this->pass );
if(!$con){
$this->error = mysql_error();
$this->msgerror = $MESSAGE["CONECTIONERROR"] ;
if ($this->debug<>0) mysql_error(); // debug
}
else{
$database = mysql_select_db($this->database,$con);
if(!$database){
$this->error = mysql_error();
$this->msgerror = $MESSAGE["DATABASEERROR"] ;
if ($this->debug<>0) mysql_error();// debug
}
else{
$this->ConId = $con;
}
}
if ($this->debug<>0) echo $MESSAGE["CONNECTED"] ; // debug
if ($this->error>0) echo $this->msgerror;
} // final da função connect
# executa uma consulta a base de dados MySQL ################################################ Revisão 26/08/2002 #
function select( $sql ) {
if (preg_match("/delete/i", $sql)) { Exit; }
if (preg_match("/update/i", $sql)) { Exit; }
if (preg_match("/insert/i", $sql)) { Exit; }
$res = @mysql_query($sql, $this->ConId );
if(!$res){
echo $MESSAGE["QUERYERROR"] . mysql_error();
$this->msgerror = mysql_error();
}
else{
$this->recordcount = mysql_num_rows($res);
return $res;
}
}
# executa um comando em uma base de dadosMySQL ################################################ Revisão 26/08/2002 #
function Execute( $sql ) {
$res = @mysql_query($sql, $this->ConId );
if(!$res){
echo $MESSAGE["COMMANDERROR"] . mysql_error();
$this->msgerror = mysql_error();
}
else{
$this->recordcount = 0;
return $res;
}
}
}// final da classe
?>
|