【发布时间】:2013-04-13 03:17:37
【问题描述】:
我有一个 PostgreSQL 数据库 userdb 有 5 个模式。
Schema 1- Persons
Schema 2- Project
Schema 3- Shop
Schema 4- Test
我能够使用pg_connect 连接到数据库。如何访问该数据库中的特定架构?
当数据库中只有一个模式时,我能够连接到模式。但现在由于我有多个架构,我很难访问任何特定的架构。
<?php
// attempt a connection
$dbh = pg_connect("host=**.****.*******.*** dbname=test user=merlin port=5433 password=passw123");
if (!$dbh) {
die("Error in connection test: " . pg_last_error());
}
// execute query
$sql = "SELECT * FROM test.country";
$result = pg_query($dbh, $sql);
if (!$result) {
die("Error in SQL query: " . pg_last_error());
}
// iterate over result set
// print each row
while ($row = pg_fetch_array($result)) {
echo "Country code: " . $row[0] . "<br />";
echo "Country name: " . $row[1] . "<p />";
}
// free memory
pg_free_result($result);
// close connection
pg_close($dbh);
?>
【问题讨论】:
-
你遇到了什么困难?
-
它给了我这个错误:
Error in SQL query: ERROR: relation "aircraft" does not exist at character 15.Aircraft 是我的一个模式中的一个表。 -
表名是
aircraft还是"Aircraft"?更多关于混合大小写标识符的信息:stackoverflow.com/questions/8792912/…
标签: php database postgresql