Skip to content

Instantly share code, notes, and snippets.

@andylibrian
Created July 2, 2024 14:26
Show Gist options
  • Select an option

  • Save andylibrian/07157525d9fbe2264ee6deb7314e9b02 to your computer and use it in GitHub Desktop.

Select an option

Save andylibrian/07157525d9fbe2264ee6deb7314e9b02 to your computer and use it in GitHub Desktop.
Tmp PHP test-db-conn
<?php
// Database connection parameters
$host = "localhost";
$dbname = "your_database_name";
$user = "your_username";
$password = "your_password";
try {
// Create a new PDO instance
$pdo = new PDO("pgsql:host=$host;dbname=$dbname", $user, $password);
// Set error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Prepare and execute the query
$stmt = $pdo->query("SELECT CURRENT_TIMESTAMP");
// Fetch the result
$result = $stmt->fetch(PDO::FETCH_ASSOC);
// Print the current time
echo "Current PostgreSQL server time: " . $result['current_timestamp'];
} catch (PDOException $e) {
// Handle connection errors
die("Connection failed: " . $e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment