Ver Mensaje Individual
  #6 (permalink)  
Antiguo 05/12/2007, 17:57
Sanubrio
 
Fecha de Ingreso: septiembre-2007
Mensajes: 220
Antigüedad: 16 años, 7 meses
Puntos: 1
Re: modular php y mysql

También puedes hacerte alguna clase

Código PHP:
class mysql
{
  protected 
$servidor;
  protected 
$usuario;
  protected 
$password;
  protected 
$base;
  
  protected 
$persistente;
  
  protected 
$enlace;
  
  protected 
$resultado;  
  
  public function 
__construct($usuario$password$base$servidor 'localhost'$persistente false;)
  {
      
$this->usuario $usuario;
      
$this->password $password;
      
$this->base $base;
      
$this->servidor $servidor;
      
      
$this->persistente $persistente;
  }  
  
  protected function 
conectar()
  {
      if (
$this->enlace === null)
      {
          if (
$this->persistente)
          {
              
$funcion_conectar 'mysql_pconnect';
          }
          else
          {
              
$funcion_conectar 'mysql_connect';
          }
          
          
$this->enlace $funcion_conectar($this->servidor$this->usuario$this->password);
          
          if (!
$this->enlace)
          {
              die(
'Error al conectar a la Base de Datos');
          }
          
          
$this->seleccionarBase();
      }
  }
  
  protected function 
seleccionarBase()
  {
      if (
$this->enlace)
      {
          if (!
mysql_select_db($this->base$this->enlace))
          {
              die(
"Error al seleccionar la Base de Datos");
          }
      }
  }
  
  public function 
escape($cadena)
  {
      
$this->conectar();
      
      return 
mysql_real_escape_string($cadena);
  }
  
  public function 
limpiar()
  {
      
$this->resultado null;
  }
  
  public function 
query($query)
  {
      
$this->conectar();
      
      
$this->resultado mysql_query($query$this->enlace);
  }
  
  public function 
fetch_array()
  {
      if (
$this->resultado)
      {
          return 
mysql_fetch_array($resultado);
      }
      
      return 
false;
  }