HEROKU CONNECTで接続されたPOSTGREを一覧表示

salesforceのオブジェクトを呼び出す場合は、

select * from salesforce.account

という感じです!

 

@@@

 

<HTML>
<HEAD>
<TITLE>LIST</TITLE>
</HEAD>
<BODY>
<H1>LIST!</H1>
<?php
$url = parse_url(getenv('DATABASE_URL'));
$dsn = sprintf('pgsql:host=%s;dbname=%s', $url['host'], substr($url['path'], 1));

$dbh = new PDO($dsn, $url['user'], $url['pass']);
echo "DB Connected!<BR/>\n";
$dbh -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "select * from salesforce.account";
$stmt = $dbh -> query($sql);
echo "SQL on !<BR/>\n";
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "RESULT!<BR/><BR/>\n";
# print_r($result);
foreach ($result as $row){
echo $row['name'] . "<BR/>\n";
}
$dbh = null;
?>

</BODY>
</HTML>