Skip to content
Snippets Groups Projects
db_link.php 701 B
Newer Older
<?php
// Connecting, selecting database
$user = ""; 
$pass = ""; 
$db = "test"; 

$con = pg_connect("dbname=$db user=$user password=$pass")
    or die ("Could not connect to server\n"); 

// Performing SQL query
$query = 'SELECT * FROM agency limit 10';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());

// Printing results in HTML
//echo "<table>\n";
//while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
//    echo "\t<tr>\n";
//    foreach ($line as $col_value) {
//        echo "\t\t<td>$col_value</td>\n";
//    }
//    echo "\t</tr>\n";
//}
//echo "</table>\n";

echo "done\n";

// Free resultset
pg_free_result($result);

// Closing connection
pg_close($con);
?>