How To Test Connection Postgres SQL With PHP

If you want test connection to Database Postgresql with PHP, you can try my code. Please look at the below example code for connection Postgres.

    $connection = pg_connect ("host=localhost dbname=postgres user=postgres password=20Cimanggu");
    if($connection) {
       echo 'connected';
    } else {
        echo 'there has been an error connecting';

After that you can try access, look if output success connection "connected" but if connection error. Please check pg_connect helper using module PHP (php_pgsql).


if you want look list enable Module, you can try running this syntak.

$ php -m


Related Articles