note 67938 deleted from ref.pgsql by nlopess
| From: | nlopess@php.net | Date: | Fri, 07 Jul 2006 09:40:27 +0000 |
| Subject: | note 67938 deleted from ref.pgsql by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114531@lists.php.net to get a copy of this message | ||
Note Submitter: framirez at akori dot fr
Reason: non-english
----
/*
@author: FabÃan Andrés RamÃrez Sepúlveda
@owner : Proyecto
@email : framirez@akori.fr
@clase : framework->postgresql.php
@desc : Clase para la conexion con una base de datos PostgreSQL
$Id: postgresql.php 133 2006-07-06 20:30:23Z framirez $
*/
class postgresql
{
var $enlace;
/* conecta con la db*/
function conectar()
{
if (!$this->enlace=pg_connect("host=localhost port=5432 user=framirez password=15550
dbname=framirez", PGSQL_CONNECT_FORCE_NEW))
{
die('Error conectando con la base de datos: ' . $host);
}
}
/* Realiza las consultas */
function consulta($sentenciaSQL)
{
if(!$this->consulta=pg_exec($sentenciaSQL))
{
die('Error realizando la consulta: ' . $sentenciaSQL);
}
}
/* Obtiene los resultados */
function obtenerResultado(){
$this->resultado=pg_fetch_Array($this->consulta);
return $this->resultado;
}
/* Desconecta de la base de datos */
function desconectar()
{
$this->desconectar=pg_close();
}
/* Funciones adicionales */
function version()
{
$version = pg_version($this->enlace);
return $version;
}
}
To execute:
/* Invocación de la clase */
$postgresql = new postgresql();
$postgresql->conectar();
$postgresql->consulta("SELECT * from noticias");
while($source=$postgresql->obtenerResultado()){
printf($source['idnoticia']);
}
$postgresql->desconectar();
/* Fin de la invocación a la clase */