通过 PHP 访问 PostgreSQL 数据库中的特定模式

beg*_*.py 0 php database postgresql

我有一个userdb带有 5 个模式的 PostgreSQL 数据库。

Schema 1- Persons
Schema 2- Project
Schema 3- Shop
Schema 4- Test
Run Code Online (Sandbox Code Playgroud)

我能够使用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);      
?>
Run Code Online (Sandbox Code Playgroud)

Clo*_*eto 5

使用模式名称限定表

select *
from my_schema.aircraft
Run Code Online (Sandbox Code Playgroud)