Created
April 11, 2023 20:09
-
-
Save robertopc/649388e23de26534335d5b7d0fce1625 to your computer and use it in GitHub Desktop.
Test PostgreSQL and MySQL/MariaDB connectivity with PHP
This file contains 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 | |
$servername = "localhost"; | |
$username = "user"; | |
$password = "password"; | |
echo"Postgre connection test<br>"; | |
try { | |
$conn = new PDO("pgsql:host=$servername;dbname=test", $username, $password); | |
// set the PDO error mode to exception | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
echo "Connected successfully"; | |
} catch(PDOException $e) { | |
echo "Connection failed: " . $e->getMessage(); | |
} | |
echo "<hr>Mariadb connection test<br>"; | |
try { | |
$conn = new PDO("mysql:host=$servername;dbname=test", $username, $password); | |
// set the PDO error mode to exception | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
echo "Connected successfully"; | |
} catch(PDOException $e) { | |
echo "Connection failed: " . $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment