How to connect to PostgreSQL using PHP native functions?

  • Use the PHP code to connect to PostgreSQL and select a database.
  • Replace 'username' with your username, 'password' with your password, and 'dbname' with the database name
<?php
    $db_connection = pg_connect("host=localhost dbname=dbname user=username password=password");
?>

After connection is made to PostgreSQL and select the database. Now you can run SQL queries and other operations also.
Was this answer helpful?

Related Articles

How to connect PostgreSQL using psql?

Log in to your Hostginger hosting account. Replace 'dbname' with the name of the database, and...

How to connect to PostgreSQL using PDO (PHP Data Objects)?

PHP Data focus upon abstract database access, and enables you to use code that can handle...

How to connect to PostgreSQL using Python psycopg2 package?

To access PostgreSQL databases using Python, you must install psycopg2 package in a virtual...

How to connect to PostgreSQL using Python PyGreSQL?

To access PostgreSQL databases using Python, you must install PyGreSQL package in a virtual...

How to connect to PostgreSQL using Perl Database Interface Module?

Your Perl scripts can connect to PostgreSQL databases using the DBI (Database Interface) module....