Welcome 歡迎光臨! 愛上網路-原本退步是向前 !

postgresql資料庫檢測程式

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;
}

 

[ 資料庫 ] 瀏覽次數 : 32 更新日期 : 2024/11/07