When you need to quickly test a database connection you can use the following scripts:
<?php
$dbHost = '127.0.0.1';
$dbName = 'testdb';
$dbUser = 'root';
$dbPass = '-add-password-here-';
try {
$db = new pdo('mysql:host='.$dbHost.';port=3306;dbname='.$dbName.';charset=utf8', $dbUser, $dbPass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
} catch (PDOException $pe) {
echo $pe->getMessage();
die("\n");
}
echo "-- Successfully connected to database --";
<?php
$dbHost = '127.0.0.1';
$dbName = 'testdb';
$dbUser = 'postgres';
$dbPass = '-add-password-here-';
try {
$db = new pdo('pgsql:host='.$dbHost.';port=5432;dbname='.$dbName, $dbUser, $dbPass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
} catch (PDOException $pe) {
echo $pe->getMessage();
die("\n");
}
echo "-- Successfully connected to database --";