我无法连接到我的数据库。当然,我只是缺少一些简单的东西:
$host = "localhost";
$port = "5432";
$db_name = 'db';
$username = "user";
$password = "pass";
$dbh = new PDO("pgsql:dbname=$db_name; host=$host", $username, $password );
$dbh->setAttribute( PDO::ATTR_ERRMODE , PDO::ERRMODE_EXCEPTION );
$sth = $dbh->prepare("
SELECT *
FROM test1
WHERE id = :id
");
$sth->bindValue(':id', 1, PDO::PARAM_STR);
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
我得到错误
致命错误:未捕获的异常 'PDOException' 带有消息'SQLSTATE [42P01]:未定义的表:7 错误:关系“test1”不存在第 3 行:FROM test1 ^' in ... [url] ... 地址堆栈跟踪: #0 ...[url]... PDOStatement->execute() #1 {main} 在 ...[url] 中抛出
谢谢!