title: Access a specific schema in a PostgreSQL database via PHP
body: <p>I have a PostgreSQL database <code>userdb</code> with 5 schemas. </p>
  
  <pre><code>Schema 1- Persons
  Schema 2- Project
  Schema 3- Shop
  Schema 4- Test
  </code></pre>
  
  <p>I was able to connect to the database using <code>pg_connect</code>. How do I access a specific schema in that database?</p>
  
  <p>I was able to connect to a schema when there was only one in the database. But now since I have multiple schemas I am having difficulty in accessing any specific one.</p>
  
  <pre><code> &lt;?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] . "&lt;br /&gt;";
       echo "Country name: " . $row[1] . "&lt;p /&gt;";
   }       
  
   // free memory
   pg_free_result($result);       
  
   // close connection
   pg_close($dbh);      
  ?&gt;
  </code></pre>