Accessing Postgres via PHP

Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Connection refused Is the server running on host "localhost" ( and accepting TCP/IP connections on port 5432? in /home/staff/acad/cm1958/public_html/webdatabases/php/pgExample.php on line 45

Fatal error: Uncaught TypeError: pg_exec(): Argument #1 ($connection) must be of type PgSql\Connection, bool given in /home/staff/acad/cm1958/public_html/webdatabases/php/pgExample.php:9 Stack trace: #0 /home/staff/acad/cm1958/public_html/webdatabases/php/pgExample.php(9): pg_exec() #1 /home/staff/acad/cm1958/public_html/webdatabases/php/pgExample.php(48): select_data() #2 {main} thrown in /home/staff/acad/cm1958/public_html/webdatabases/php/pgExample.php on line 9