dnf install php-pgsql
用來檢查資料庫是否連結沒有問題,看看是否都有安裝到相關的元件
$host = 'localhost';
$db = 'XXXX';
$user = 'UUUUUUU';
$pass = 'PPPPPPP';
$port = '5432';
===================================
$db_handle = pg_connect("host={$host} port={$port} dbname={$db} user={$user} password={$pass}");
if ($db_handle) {
echo "\nConnection attempt succeeded. \n\n";
} else {
echo "\nConnection attempt failed. \n\n";
}
echo "Connection Information\n";
echo "======================\n\n";
echo "DATABASE NAME:" . pg_dbname($db_handle) . "\n";
echo "HOSTNAME: " . pg_host($db_handle) . "\n";
echo "PORT: " . pg_port($db_handle) . "\n\n";
=========================
在 php.ini 中找到 extension=pdo_pgsql 並把他取消註解
extension=pdo_pgsql
try {
$pgConn = new PDO("pgsql:host=$host;port=$port;db=$dbname;", $user, $pass);
} catch (PDOException $e) {
echo 'Database connection fails: ' . $e->getMessage() . '
';
exit;
}