★ wanayoo — archive 1999 http://www.php.net/manual/ref.pgsql.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Function Reference
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Function Reference
* Apache
* Arrays
* Aspell
* BC math
* Calendar
* CCVS
* COM
* Classes/Objects
* ClibPDF
* CURL
* Cybercash
* dba
* Date/time
* dBase
* DBM
* Directories
* Dyn.loading
* DOM XML
* filePro
* Filesystem
* FDF
* FTP
* gettext
* HTTP
* Hyperwave
* ICAP
* Graphics
* IMAP
* Informix
* InterBase
* LDAP
* Mail
* Math.
* MCAL
* mcrypt
* mhash
* MS SQL Server
* Misc.
* mSQL
* MySQL
* Network
* ODBC
* Oracle
* OCI8
* PDF
* Verisign Payflow Pro
* PHP options/info
* POSIX
* PostgreSQL
* Program Execution
* Pspell
* readline
* Recode
* PCRE
* Regexps
* Semaphore
* Sessions
* SWF
* SNMP
* Strings
* Sybase
* URLs
* Variables
* Vmailmgr
* WDDX
* XML
* YAZ
* YP/NIS
* Zlib
Manual: PostgreSQL functions
View the source code for this pageSearch the site



Previous page
 posix_getrlimit
 Updated
Sat, 12 Aug 2000
pg_close 
Next page


XLIX. PostgreSQL functions

Postgres, developed originally in the UC Berkeley Computer Science Department, pioneered many of the object-relational concepts now becoming available in some commercial databases. It provides SQL92/SQL3 language support, transaction integrity, and type extensibility. PostgreSQL is a public-domain, open source descendant of this original Berkeley code.

PostgreSQL is available without cost. The current version is available at www.PostgreSQL.org.

Since version 6.3 (03/02/1998) PostgreSQL uses unix domain sockets. A table is shown below describing these new connection possibilities. This socket will be found in /tmp/.s.PGSQL.5432. This option can be enabled with the '-i' flag to postmaster and it's meaning is: "listen on TCP/IP sockets as well as Unix domain sockets".

Table 1. Postmaster and PHP

PostmasterPHPStatus
postmaster &pg_connect("", "", "", "", "dbname");OK
postmaster -i &pg_connect("", "", "", "", "dbname");OK
postmaster &pg_connect("localhost", "", "", "", "dbname"); Unable to connect to PostgreSQL server: connectDB() failed: Is the postmaster running and accepting TCP/IP (with -i) connection at 'localhost' on port '5432'? in /path/to/file.php3 on line 20.
postmaster -i &pg_connect("localhost", "", "", "", "dbname");OK

One can also establish a connection with the following command: $conn = pg_Connect("host=localhost port=5432 dbname=chris");

To use the large object (lo) interface, it is necessary to enclose it within a transaction block. A transaction block starts with a begin and if the transaction was valid ends with commit or end. If the transaction fails the transaction should be closed with rollback or abort.

Example 1. Using Large Objects


<?php
    $database = pg_Connect ("", "", "", "", "jacarta");
    pg_exec ($database, "begin");
    $oid = pg_locreate ($database);
    echo ("$oid\n");
    $handle = pg_loopen ($database, $oid, "w");
    echo ("$handle\n");
    pg_lowrite ($handle, "gaga");
    pg_loclose ($handle);
    pg_exec ($database, "commit");
?>
     

Table of Contents
pg_close — Close a PostgreSQL connection
pg_cmdtuples — Returns number of affected tuples
pg_connect — Open a PostgreSQL connection
pg_dbname — Get the database name
pg_errormessage — Get the error message string
pg_exec — Execute a query
pg_fetch_array — Fetch a row as an array
pg_fetch_object — Fetch a row as an object
pg_fetch_row — Get a row as an enumerated array
pg_fieldisnull — Test if a field is NULL
pg_fieldname — Returns the name of a field
pg_fieldnum — Returns the field number of the named field
pg_fieldprtlen — Returns the printed length
pg_fieldsize — Returns the internal storage size of the named field
pg_fieldtype — Returns the type name for the corresponding field number
pg_freeresult — Free reult memory
pg_getlastoid — Returns the last object identifier
pg_host — Returns the host name associated with the connection
pg_loclose — Close a large object
pg_locreate — Create a large object
pg_loexport — Export a large object to file
pg_loimport — Import a large object from file
pg_loopen — Open a large object
pg_loread — Read a large object
pg_loreadall — Read a entire large object and send straight to browser
pg_lounlink — Delete a large object
pg_lowrite — Write a large object
pg_numfields — Returns the number of fields
pg_numrows — Returns the number of rows
pg_options — Get the options associated with the connection
pg_pconnect — Open a persistent PostgreSQL connection
pg_port — Return the port number associated with the connection
pg_result — Returns values from a result identifier
pg_trace — Enable tracing a PostgreSQL connection
pg_tty — Return the tty name associated with the connection
pg_untrace — Disable tracing of a PostgreSQL connection

User Contributed Notes: PostgreSQL functions


trurl@realtor3d.odessa.ua
13-Sep-1999 08:23
in example on first pg_* manual page:


...
pg_loclose ($handle);

pg_exec ($database, "commit")

pg_exec ($database, "end")

?>
...

is missing ';' in the eol.



nick@wwf.org.co
16-Feb-2000 04:57
PG supports the "CREATE DATABASE " SQL statement, so I guess you could just give that to the pg_Exec to create a database.


bleach@chek.com
02-Mar-2000 12:36
If you want to see all the objects in a database, you can find that information in the pg_class table.

SELECT * FROM pg_class;

Now this is going to be kind of long and complex, to see how psql command handles the \d and other things. use the syntax. psql -E <Database>, ie psql -E mydatabase

What this will do is show the SQL command used for everything. So when you type a \d or something, it shows the SQL query used for the result.




22-Mar-2000 03:42
Trap errors with


if (pg_numrows($rsExp) > 0)



andy@harmonyworks.com
06-Apr-2000 11:42
Postgres vs. MySQL


Postgres: Transactions, unlimited database size, rich feature types (polygon, arrays), inheritence, online backups.


MySQL: Fast, 2GB database size limit, no transactions, manual query optimization.


Depends what you want, both are very good. MySQL = speed, Postgres = safety



stefan.doehla@rrze.uni-erlangen.de
17-Apr-2000 12:50
A way to connect as a specific user/ password: don't use commas with the following syntax.

("host=Host port=Port user=User password=Password dbname=Dbname")




18-May-2000 05:29
Ways of getting the value of a generated serial are discussed at http://www.postgresql.org/docs/faq-english.html#4.16.2


 About Notes


Previous page
 posix_getrlimit
 Updated
Sat, 12 Aug 2000
pg_close 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.