Ver Mensaje Individual
  #3 (permalink)  
Antiguo 23/01/2005, 14:31
Avatar de Reynier
Reynier
 
Fecha de Ingreso: noviembre-2002
Ubicación: Por ahí en algún sitio
Mensajes: 1.844
Antigüedad: 23 años, 10 meses
Puntos: 1
Parte 3

Código PHP:
 // Clase para BDatos MySQL
 
class MySQL{
  var 
$host;     // (string)  Servidor Host donde se haya la BDatos, puede ser el IP o el nombre de dominio
                 // IP : $host = "xxx.xxx.xxx.xxx";
                 // Nombre de Dominio : $host = "www.miservidor.com";
  
var $user;     // (string)  Usuario de conexión a BDatos
  
var $password; // (string)  Contraseña de Conexión a BDatos
  
var $db_name;  // (string)  Base de Datos con la cual se trabajará
  
var $port;     // (int)     Puerto por donde será accedida la BDatos

  
function MySQL($host = "", $user = "", $password = "", $db_name = "", $port = ""){
   
$this->host     = ($host != "")      ?  (string)$host      :  "localhost";
   
$this->user     = ($user != "")      ?  (string)$user      :  "root";
   
$this->password = ($password != "")  ?  (string)$password  :  "";
   
$this->db_name  = ($db_name != "")   ?  (string)$db_name   :  "";
   
$this->port     = ($port != "")      ?  (int)$port         :  3306;
  }

  function 
connect(&$connection, $db_name, $is_persistent = false){
   
$db_name = ($db_name != "")  ?  $db_name  :  $this->db_name;
   if (!
$is_persistent){
    
$connection = @mysql_connect($this->host.':'.$this->port, $this->user, $this->password);
   }else{
    
$connection = @mysql_pconnect($this->host.':'.$this->port, $this->user, $this->password);
   }
   if (!
$connection  ||  !@mysql_select_db($db_name, $connection)){
    return 
false;
   }
   return 
$connection;
  }

  function 
disconnect(&$connection){
   if (
$connection){
    return @
mysql_close($connection);
   }
   return 
true;
  }

  function 
query($query, $connection){
   return @
mysql_query($query, $connection);
  }

  function 
numRows($result){
   return @
mysql_num_rows($result);
  }

  function 
affectedRows($result, $connection){
   return @
mysql_affected_rows($connection);
  }

  function 
fetchArray($result){
   return @
mysql_fetch_array($result);
  }

  function 
fetchRow($result){
   return @
mysql_fetch_row($result);
  }

  function 
fetchAssoc($result){
   return @
mysql_fetch_assoc($result);
  }

  function 
escape($string){
   return @
mysql_escape_string($string);
  }

  function 
error($connection){
   return 
mysql_error($connection);
  }
 }

 class 
PostGreSQL{
  var 
$host;     // (string)  Servidor Host donde se haya la BDatos, puede ser el IP o el nombre de dominio
                 // IP : $host = "xxx.xxx.xxx.xxx";
                 // Nombre de Dominio : $host = "www.miservidor.com";
  
var $user;     // (string)  Usuario de conexión a BDatos
  
var $password; // (string)  Contraseña de Conexión a BDatos
  
var $db_name;  // (string)  Base de Datos con la cual se trabajará
  
var $port;     // (int)     Puerto por donde será accedida la BDatos

  
function PostGreSQL($host = "", $user = "", $password = "", $db_name = "", $port = ""){
   
$this->host     = ($host != "")      ?  (string)$host      :  "localhost";
   
$this->user     = ($user != "")      ?  (string)$user      :  "root";
   
$this->password = ($password != "")  ?  (string)$password  :  "";
   
$this->db_name  = ($db_name != "")   ?  (string)$db_name   :  "";
   
$this->port     = ($port != "")      ?  (int)$port         :  5432;
  }

  function 
connect(&$connection, $db_name, $is_persistent = false){
   
$db_name = ($db_name != "")  ?  $db_name  :  $this->db_name;
   
$connection_string = 'host=' . $this->host . ' port=' . $this->port . ' user=' . $this->user . ' password=' . $this->password . ' dbname=' . $db_name;
   if(!
$is_persistent){
    
$connection = @pg_connect($connection_string, PGSQL_CONNECT_FORCE_NEW);
   }else{
    
$connection = @pg_pconnect($connection_string, PGSQL_CONNECT_FORCE_NEW);
   }
   if (!
$connection){
    return 
false;
   }
   return 
$connection;
  }

  function 
disconnect(&$connection){
   if(
$connection){
    return @
pg_close($connection);
   }
   return 
true;
  }

  function 
query($query, $connection){
   return @
pg_query($connection, $query);
  }

  function 
affectedRows($result, $connection){
   return @
pg_affected_rows($result);
  }

  function 
numRows($result){
   return @
pg_num_rows($result);
  }

  function 
fetchArray($result){
   return @
pg_fetch_array($result);
  }

  function 
fetchRow($result){
   return @
pg_fetch_row($result);
  }

  function 
fetchAssoc($result){
   return @
pg_fetch_assoc($result);
  }

  function 
escape($string){
   return @
mysql_escape_string($string);
  }

  function 
error($connection){
   return 
pg_last_error($connection);
  }
 } 
__________________
Ing. Reynier Pérez Mira