PostgreSQL
From RadPHP XE2 Documentation
Contents |
Initial Setup
To get PHP and PostgreSQL working together, follow these steps:
- Get PostgreSQL Installer from postgresql.org/download/windows.
- Install it in your system.
- 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
- php.net/manual/book.pgsql.php (PostgreSQL PHP Documentation)