★ wanayoo — archive 1999 http://www.php.net/manual/function.pg-connect.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to PostgreSQL
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
PostgreSQL
* pg_close
* pg_cmdtuples
* pg_connect
* pg_dbname
* pg_errormessage
* pg_exec
* pg_fetch_array
* pg_fetch_object
* pg_fetch_row
* pg_fieldisnull
* pg_fieldname
* pg_fieldnum
* pg_fieldprtlen
* pg_fieldsize
* pg_fieldtype
* pg_freeresult
* pg_getlastoid
* pg_host
* pg_loclose
* pg_locreate
* pg_loexport
* pg_loimport
* pg_loopen
* pg_loread
* pg_loreadall
* pg_lounlink
* pg_lowrite
* pg_numfields
* pg_numrows
* pg_options
* pg_pconnect
* pg_port
* pg_result
* pg_trace
* pg_tty
* pg_untrace
Manual: pg_connect
View the source code for this pageSearch the site



Previous page
 pg_cmdtuples
 Updated
Sat, 12 Aug 2000
pg_dbname 
Next page


pg_connect

(PHP3 , PHP4 )

pg_connect -- Open a PostgreSQL connection

Description

int pg_connect (string host, string port, string options, string tty, string dbname)

Returns a connection index on success, or false if the connection could not be made. Opens a connection to a PostgreSQL database. Each of the arguments should be a quoted string, including the port number. The options and tty arguments are optional and can be left out. This function returns a connection index that is needed by other PostgreSQL functions. You can have multiple connections open at once.

A connection can also established with the following command: $conn = pg_connect("dbname=marliese port=5432"); Other parameters besides dbname and port are host, tty, options, user, and password.

See also pg_pconnect().


User Contributed Notes: pg_connect


Philippe.Rochat@epfl.ch
10-Oct-1998 01:37
It would be more explicit to give the following example for the new pg_connect syntax (especially for developpers needing user authentification when connecting to postgres via php):
pg_Connect("host=myHost port=myPort tty=myTTY options=myOptions user=myUser password=myPassword dbname=nyDB";
With any of the value pair optional ...

Ph.R.



rusty@duse.net
01-Apr-1999 05:10
pg_connect(string host, string port, string options, string tty, string dbname);

options?!?! wicht options are you talking about?!?!?!?



tadamec@blitherakt.com
05-Apr-1999 04:17
The documentation doesn't mention it, but the connection string can also specify the "user" as a parameter. For example, a minimalist connection:

<PRE>$db = pg_Connect("host=localhost user=rhubarb");</PRE>

This would assume that you have created a user named "rhubarb", a database was created with the name of "rhubarb" and you're not using any password authentication on connections made locally.



owld@mail.ru
24-Apr-1999 06:39
Hi all,
"user=User_name password=Pass_for_User"
options working , but not in documentation.



michael@apollo.cs
07-May-1999 04:08
If you use a password you can also set that as part of the connection string. Here is an example using pg_pconnect. The string inside is identical for the call pg_connect.

<PRE>
pg_pconnect("dbname=testdb user=michael password=foobar port=5433");
</PRE>



chris@cogdon.org
04-Aug-1999 10:21
If your database is local (via unix sockets rather than internet sockets) then just specify "dbname=whatever" rather than host and port.


eric@widesoft.com.br
21-Sep-1999 10:23
/* Testing Connection */
&lt;?php
$con = pg_pconnect("","","","","");
if (!$con) {
echo "Error !!!.\n";
exit;
}



krauss@b2b.com.br
21-Sep-1999 10:47

I repeat: options?!?! wicht options are you talking about?!?!?!?



krauss@b2b.com.br
21-Sep-1999 10:55
I need rapid production of scripts whith, p. ex.

psql em3 -H -T border=1 -c "select * from table"

how PHP do the "-H" and other options !!??
(the -H returns HTML formated results)





shelly_vig@hotmail.com
15-Oct-1999 02:49
which port to connect while connecting pgsql


epowell@yuck.net
31-Oct-1999 08:59
A lot of the questions that appear here can be answered by looking at the PostgreSQL programming documentation (www.postgresql.org). PHP's PostgreSQL interface appears to be heavily based on the libpq programming interface.


xtsnet@yahoo.com
24-Nov-1999 10:56
I keep getting this message when i try to connect.
/*
Fatal error: Call to unsupported or undefined function pg_connect() in /usr/local/httpd/htdocs/lvnet/connect.php3
*/

Am I missing a patch maybe ???

This is the line in the file

/*

$conn = pg_connect("host=#### user=###### password=###### dbname=######");

*/



michael_meyer@bigfoot.de
16-Dec-1999 08:38
Do I need special Librarys to connect to a PostgeSql-Server with php3 and IIS-4 under NT?
As I tried to connect with the pg_connect() function and I got the following message: Unknown function pg_connect()
I don't have this problem with Apache under Linux.
Any recommendations?



lithis@cpinternet.com
16-Jan-2000 02:04
to connect to a postgres database, you need to compile posgres support into php. see the php manual section about installation (at http://php.net/manual/install-unix.php3 ), but the quick answer is to run "./configure --with-postgres" before compiling postgres. note you'll then have to recompile apache unless you use a dso.


bobesr@yahoo.com
18-Jan-2000 11:31
URGENT PLease:
What is the difference between pg_connect and pg_pconnect ?
If the script crash (or stop) befor pg_close the connection will
be still ? If yes how can I close it ? Do I need to close it ?



azerin@oritech.po.my
26-Jan-2000 01:19
Warning: Unable to connect to PostgresSQL server: pqReadData() -- backend closed the channel unexpectedly. This probably
means the backend terminated abnormally before or while processing the request. in /home/httpd/html/test.php3 on line 2

Warning: 0 is not a PostgresSQL link index in /home/httpd/html/test.php3 on line 3

Warning: 0 is not a PostgresSQL result index in /home/httpd/html/test.php3 on line 4
<- cmdtuples affected.
what is the error of it
my code is
<pre>
&lt;?php
$conn = pg_connect("localhost", "5432", "ayen", "WKZZhdxN", "template1");
$result = pg_exec($conn, "select * from template1");
$cmdtuples = pg_cmdtuples($result);
echo $cmdtuples . " <- cmdtuples affected.";
?></pre>



inquiry@vdmi.com.sg
20-Mar-2000 03:10
I find this works for those of you using remote db servers and user/password option:

$server = "host";
$port = "5432";
$user = "blah";
$passwd = "blah";
$db = "db_blah";

$connection = pg_connect("host=$server port=$port user=$user password=$passwd dbname=$db") or pg_die();

Don't use commas. Hope this helps!



clecerf@univ-paris8.fr
23-Mar-2000 10:02
The "Options" parameter. It seems to worry some users...
Refering to the libpq doc of Postgres, it is used to set trace/debug options to be sent to backend.
Probably no use for a PHP3 programmer.



daniel@rootsys.com.br
27-Apr-2000 01:13
Im trying to use postgres with php under Linux and I cant get the pg functions of php to work. The apache server is parsing the php file, but when it gets in the pg_connect line it generates the message "function unsuported or not defined." Does anybdy know wha I have to do?


sfeley@sff.net
28-Apr-2000 07:31
Re: the pg_* functions not working: make sure you compiled PHP with the --with-pgsql configure option set. If you didn't, reconfigure, recompile and reinstall.


owen_mu@web.de
15-May-2000 10:12
$conn = pg_connect("host=localhost port=5432 dbnabe=cd"); //line 24
Waring: Unable to connect to PostgreSQL sever. FATAL1: SetUserId: user 'wwwrun' is not in pg_shadow' in /usr/local/httpd/htdocs/cd.php3 on line 24.



henkvl@cs.uu.nl
14-Jul-2000 09:22
What about: pg_Connect ("host=quatre.example.com port=5432 user=$PHP_AUTH_USER password=$PHP_AUTH_PW dbname=base");
and PHP_AUTH_PW containing a space?? It
obviously won't work so what is the alternative?



leace@post.cz
21-Jul-2000 02:26
Just a note:


If you use PostgreSQL users for authenticating into your pg database rather than using your own authentication, always specify host directive in pg_connect and edit pg_hba.conf to authenticate from this host accordingly. Otherwise, PHP will connect as 'local' using UNIX domain sockets, which is set in pg_hba.conf to 'trust' by default (so you can connect using psql on console without specifying password) and everyone can connect to db _without password_ .



 About Notes


Previous page
 pg_cmdtuples
 Updated
Sat, 12 Aug 2000
pg_dbname 
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.