Login   Register  
PHP Classes
elePHPant
Icontem

File: GafDb.inc.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Douglas M Santos  >  GafDb  >  GafDb.inc.php  >  Download  
File: GafDb.inc.php
Role: Class source
Content type: text/plain
Description: Main class
Class: GafDb
Simple MySQL database access wrapper
Author: By
Last change: Changed few methods
Date: 7 years ago
Size: 2,452 bytes
 

Contents

Class file image Download
<?
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<>0mysql_error();  // debug
        

        else{
            
$database mysql_select_db($this->database,$con);
            if(!
$database){ 
                
$this->error mysql_error();
                
$this->msgerror $MESSAGE["DATABASEERROR"] ;                                
                if (
$this->debug<>0mysql_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


?>