Skip to content

Instantly share code, notes, and snippets.

@terremoth
Last active October 3, 2024 21:41
Show Gist options
  • Save terremoth/19f1348e5a3b8a922407683ade1adb2c to your computer and use it in GitHub Desktop.
Save terremoth/19f1348e5a3b8a922407683ade1adb2c to your computer and use it in GitHub Desktop.
Test connection to the database (mysql, pgsql etc) generalist script
<?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