Skip to content

Instantly share code, notes, and snippets.

@Be1zebub
Last active August 3, 2024 00:43
Show Gist options
  • Save Be1zebub/35726658cec2aef45454a33b29999e3a to your computer and use it in GitHub Desktop.
Save Be1zebub/35726658cec2aef45454a33b29999e3a to your computer and use it in GitHub Desktop.
Script that I use for testing sql connections
<?php
$HOST = "1.1.1.1";
$DATABASE = "xxx";
$USER = "xxx";
$PASSWORD = "xxx";
$TIMEOUT = 5;
$dsn = "mysql:host={$HOST};dbname={$DATABASE};charset=utf8";
$opt = Array(
PDO::ATTR_TIMEOUT => $TIMEOUT,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
try {
$db = new PDO($dsn, $USER, $PASSWORD, $opt);
} catch (PDOException $e) {
die($e->getMessage());
} finally {
echo("success\n");
$smt = $db->query("SELECT table_name FROM information_schema.tables;");
print_r($smt->fetchAll(PDO::FETCH_COLUMN));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment