PostgreSQL

From RadPHP XE2 Documentation
Jump to: navigation, search

Contents

Initial Setup

To get PHP and PostgreSQL working together, follow these steps:

  1. Get PostgreSQL Installer from postgresql.org/download/windows.
  2. Install it in your system.
  3. Uncomment (remove the ; at the beginning) the following line on RadPHP php.ini.template file:
    ;extension=php_pgsql.dll

Usage

Database Setup

To use a Database component with PostgreSQL, set it up so it uses PostgreSQL driver:

  • DriverName: postgres.

Do not forget to fill also the rest of the basic information.

Work With PHP

// Set Connection Data
$database = 'database';			// Database name.
$user = 'user';				// Username to access the database.
$password = 'password';			// Password for the user.
$server = 'server'			// Server address.
 
// Establish Connection
$connection = pg_connect("host=$server dbname=$database user=$user password=$password");
 
// Connection Test
if (!$connection)
    echo 'PostgreSQL Database could not be reached';
else
    echo 'Succesfully connected to PostgreSQL Database';
 
// Perform a Query
$query = 'SELECT * FROM table';
$result = pg_query($query);
	// …
pg_free_result($resultado);
 
// Close Connection
pg_close($connection);

See Also

Personal tools