postgresql.class.php
gehe zur Dokumentation dieser Datei00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 ?>