Code for PostgreSQL reference to PHP
// Create connection string
$conn_string = “host=$host port=$port dbname=$db consumer=$consumer password=$go”;
// Set up a connection to the PostgreSQL database
$conn = pg_connect($conn_string);
if (!$conn) {
echo “Error: Unable to open databasen”;
exit;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php // Database configuration $host = ‘localhost’; $db = ‘database_name’; $consumer = ‘postgres’; // by default its postgres $go = ‘database_user_password’; $port = ‘5432’; // Default port for PostgreSQL
// Create connection string $conn_string = “host=$host port=$port dbname=$db consumer=$consumer password=$go”;
// Set up a connection to the PostgreSQL database $conn = pg_connect($conn_string);
if (!$conn) { echo “Error: Unable to open databasen”; exit; } |
1. Within the under we can outline our hostname. For native, you should use localhost. If you wish to entry the opposite host then put that hostname or Server IP right here
2. Right here we outline our database title
$db = ‘database_name’; |
3. This code for DB consumer title. For native we use postgre its default username. However you’ll be able to create db consumer title no matter you need.
4. Right here we will outline db password.
$go = ‘database_user_password’; |
5. Right here we will outline the Postgre submit quantity. By default port no is 5432
6. The pg_connect operate opens a brand new connection to the MySQL server.
// Create connection string $conn_string = “host=$host port=$port dbname=$db consumer=$consumer password=$go”; // Set up a connection to the PostgreSQL database $conn = pg_connect($conn_string); |
NOTE: For utilizing Postgre Database with PHP, it’s essential allow the pgsql
extension in php.in.