Skip to content

Instantly share code, notes, and snippets.

@ahelord
Last active February 24, 2022 06:41
Show Gist options
  • Save ahelord/59193c0c4aaa01238127031087c42c55 to your computer and use it in GitHub Desktop.
Save ahelord/59193c0c4aaa01238127031087c42c55 to your computer and use it in GitHub Desktop.
Php connect postgres
<?php
$ip = $_SERVER['REMOTE_ADDR'];
// display it back
echo "<h1>Internal Load Balancing Lab</h1>";
echo "<h2>Client IP</h2>";
echo "Your IP address : " . $ip;
echo "<h2>Hostname</h2>";
echo "Server Hostname: " . php_uname("n"). "<br>";
echo "Region and Zone: " . "region-here". "<br>";
$db_handle = pg_connect("host=35.226.49.26 dbname=dbcct user=usercct password=cct2021");
if ($db_handle) {
echo 'Connection with DB attempt succeeded. <br>';
} else {
echo 'Connection with DB attempt failed. <br>';
}
echo "<h3>Connection Information</h3>";
echo "DATABASE NAME:" . pg_dbname($db_handle) . "<br>";
echo "HOSTNAME: " . pg_host($db_handle) . "<br>";
echo "PORT: " . pg_port($db_handle) . "<br>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment