CakeFest 2024: The Official CakePHP Conference

基本的な使用法

この例では、PostgreSQL への接続・クエリの実行・結果の表示 そして切断の方法を説明します。

例1 PostgreSQL 拡張モジュールの概要

<?php
// 接続し、データベースを選択する
$dbconn = pg_connect("host=localhost dbname=publishing user=www password=foo")
or die(
'Could not connect: ' . pg_last_error());

// SQL クエリを実行する
$query = 'SELECT * FROM authors';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());

// 結果を 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";

// 結果セットを開放する
pg_free_result($result);

// 接続をクローズする
pg_close($dbconn);
?>

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top