Skip to content

Instantly share code, notes, and snippets.

@joeworkman
Created January 19, 2026 20:30
Show Gist options
  • Select an option

  • Save joeworkman/8e93be1e0244891e795bc2a57e51e061 to your computer and use it in GitHub Desktop.

Select an option

Save joeworkman/8e93be1e0244891e795bc2a57e51e061 to your computer and use it in GitHub Desktop.
This is just a simple PHP script to help you test a DB connection
<?php
$host = '127.0.0.1'; // or 'localhost'
$db = 'your_database';
$user = 'your_username';
$pass = 'your_password';
$port = 3306; // default MySQL port
$dsn = "mysql:host=$host;port=$port;dbname=$db;charset=utf8mb4";
try {
$pdo = new PDO($dsn, $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_TIMEOUT => 5,
]);
echo "✅ Connected successfully to MySQL via PDO.";
} catch (PDOException $e) {
echo "❌ Connection failed:<br>";
echo htmlspecialchars($e->getMessage(), ENT_QUOTES);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment