Last active
October 3, 2024 21:41
-
-
Save terremoth/19f1348e5a3b8a922407683ade1adb2c to your computer and use it in GitHub Desktop.
Test connection to the database (mysql, pgsql etc) generalist script
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 | |
// change credentials below and then run this php script from terminal | |
$driver = 'mysql'; | |
$host = 'localhost'; | |
$port = 3306; | |
$dbname = 'test'; | |
$user = 'root'; | |
$password = ''; | |
try { | |
$conn = new PDO("$driver:host=$host;port=$port;dbname=$dbname", $user, $password); | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
if ($conn) { | |
echo "Connected Succesfully!\n"; | |
} | |
} catch (PDOException $e) { | |
echo 'ERROR: ' . $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment