integer pg_connect(string host, string port, string options,
string database)
integer pg_connect(string host, string port, string options,
string tty, string database)
The pg_connect function returns a connection identifier to a PostgreSQL database. The
prototype displayed above is actually only one of several configurations for the
arguments.
If you provide only one argument, then it is assumed to be a connection string. This
should be in the style expected by PostgreSQL. If you provide three arguments,
pg_connect expects host, port, and database, in that order. If you provide four
arguments, pg_connect expects host, port, options, and database. Finally, you may
provide all five arguments in the order described in the last prototype. If blanks are used
for any argument, a sensible default will be used.
Compare this function to pg_pconnect. See pg_exec for an example of use.
string pg_dbname(integer connection)
Use pg_dbname to get the name of the current database. See pg_exec for an example of
use.
string pg_errormessage(integer connection)
The pg_errormessage function returns the error message for the last database action.
See pg_exec for an example of use.
integer pg_exec(integer connection, string query)
The pg_exec function executes a query on the given connection. A result identifier is
returned.
<?
//connect to database
if(!($Connection = pg_connect("", "", "", "", "leon")))
{
print("Could not establish connection.
\n");
exit;
}
//print information about connection
print("Connection established
\n");
print("Host: ". pg_host($Connection). "
\n");
print("Port: ". pg_port($Connection). "
\n");
print("Database: ". pg_dbname($connection). "
\n");
print("Options: ". pg_options($connection). "
\n");