【发布时间】:2022-01-29 07:51:27
【问题描述】:
我在我的 ubuntu 20.04 版本中安装了 lamp、phpmyadmin 和 postgresql。 以下是链接: 1.https://www.linuxbabe.com/ubuntu/install-lamp-stack-ubuntu-20-04-server-desktop
2.https://www.linuxbabe.com/ubuntu/install-phpmyadmin-apache-lamp-ubuntu-20-04
3.https://tecadmin.net/how-to-install-postgresql-in-ubuntu-20-04
之后,我做了以下操作
1. php.ini 文件中未注释的扩展 pgsql 和 pdo_pgsql
2.pg_hba.conf文件中的给定信任方法
3.将数据库 my_db 上的所有权限授予 postgres;
我已经成功地将我的数据库安装在 pgadmin4 中。但我无法连接到它。 下面是我的连接文件。用户 'postgres'@'localhost' 拒绝访问(使用密码:否)错误。我不知道我错过了什么?
<?php
$host = "localhost";
$db_name = "my_db";
$db_username = "postgres";
$db_password = "";
try {
$dbConnection = new PDO("mysql:dbname=$db_name;host=$host;charset=utf8", "$db_username", "$db_password");
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
echo $e->getMessage();
}
?>
【问题讨论】:
标签: php postgresql pdo