Client 1—Connecting to the Server

The first PHP/PostgreSQL client establishes a connection to a PostgreSQL server and displays the name of the database to which you connect. Listing 15.4 shows the client1a.php script.

Listing 15.4. client1a.php
  1 <?php
  2   //Filename: client1a.php
  3
  4   $connect_string = "dbname=movies user=bruce";
  5
  6   $db_handle = pg_connect( $connect_string );
  7
  8   echo "<HTML>\n";
  9   echo   "<HEAD>\n";
 10   echo     "<TITLE>client1</TITLE>\n";
 11   echo   "<BODY>\n";
12   echo     "<CENTER>";
 13   echo       "Connected to " . pg_dbname( $db_handle );
 14   echo     "</CENTER>\n";
 15   echo   "</BODY>\n";
 16   echo "</HTML>";
 17 ?>

This script connects to a database whose name is hard-coded in the script (at line 4). At line 6, you attempt to make a connection by calling ...

Get PostgreSQL, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.