postgresql.class.php

gehe zur Dokumentation dieser Datei
00001 <?php
00002 
00003 //
00004 // +----------------------------------------------------------------------+
00005 // | PHP version 4.0                                                      |
00006 // +----------------------------------------------------------------------+
00007 // | Copyright (c) 1997-2001 The PHP Group                                |
00008 // +----------------------------------------------------------------------+
00009 // | This source file is subject to version 2.02 of the PHP license,      |
00010 // | that is bundled with this package in the file LICENSE, and is        |
00011 // | available at through the world-wide-web at                           |
00012 // | http://www.php.net/license/2_02.txt.                                 |
00013 // | If you did not receive a copy of the PHP license and are unable to   |
00014 // | obtain it through the world-wide-web, please send a note to          |
00015 // | license@php.net so we can mail you a copy immediately.               |
00016 // +----------------------------------------------------------------------+
00017 // | Authors: Stig Bakken <ssb@fast.no>                                   |
00018 // |          Jan Dankert <phpdb@jandankert.de>                           |
00019 // +----------------------------------------------------------------------+
00020 //
00021 
00028 class DB_postgresql
00029 {
00030      var $connection;
00031 
00032 
00039      function connect( $conf )
00040      {
00041           $host   = $conf['host'];
00042           $user   = $conf['user'];
00043           $pw     = $conf['password'];
00044           $db     = $conf['database'];
00045 
00046           if   ( isset($conf['port']) )
00047                $host .= ':'.$conf['port'];
00048           
00049           if   ( $conf['persistent'] )
00050                $connect_function = 'pg_pconnect';
00051           else
00052                $connect_function = 'pg_connect';
00053 
00054           if    ( $pw != '' )
00055                $this->connection = @$connect_function( "host=$host dbname=$db user=$user password=$pw" );
00056           elseif ( $user != '' ) 
00057                $this->connection = @$connect_function( "host=$host dbname=$db user=$user" );
00058           elseif ( $host != '' ) 
00059                $this->connection = @$connect_function( "host=$host dbname=$db" );
00060           else 
00061                $this->connection = @$connect_function( "dbname=$db");
00062                
00063           if   ( ! is_resource($this->connection) )
00064           {
00065                $this->error = 'could not connect to database on host '.$host;
00066                return false;
00067           }
00068 
00069           return true;
00070     }
00071 
00072 
00073 
00079      function disconnect()
00080      {
00081           $ret = pg_close( $this->connection );
00082           $this->connection = null;
00083           return $ret;
00084      }
00085 
00086 
00087 
00088      function query($query)
00089      {
00090           $result = @pg_exec( $this->connection,$query );
00091 
00092           if   ( ! $result )
00093           {
00094                if   ( empty($this->error) )
00095                     $this->error = 'PostgreSQL says: '.@pg_errormessage();
00096                return FALSE;
00097           }
00098 
00099           return $result;;
00100      }
00101 
00102 
00103      function fetchRow( $result, $rownum )
00104      {
00105           return pg_fetch_array( $result,$rownum,PGSQL_ASSOC );
00106      }
00107 
00108  
00109      function freeResult($result)
00110      {
00111           return pg_freeresult($result);
00112      }
00113 
00114 
00115      function numCols($result )
00116      {
00117           return pg_numfields( $result );
00118      }
00119 
00120 
00121 
00122      function numRows( $result )
00123      {
00124           return pg_numrows($result);
00125      }
00126 }
00127 
00128 ?>

Erzeugt am Thu May 14 00:55:48 2009 für OpenRat von  doxygen 1.5.8