Created
July 2, 2024 14:26
-
-
Save andylibrian/07157525d9fbe2264ee6deb7314e9b02 to your computer and use it in GitHub Desktop.
Tmp PHP test-db-conn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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