Created
January 19, 2026 20:30
-
-
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
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 | |
| $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