pg_Fetch_Object
返回类资料。
语法: object pg_fetch_object(int result, int row);
返回值: 类
函数种类: 数据库功能
本函数用来将查询结果 result 拆到类变量中。若 result 没有资料,则返回 false 值。参数 result 为使用 pg_Exec() 所返回的代码值。参数 row 为列数。
<?php $database = "verlag"; $db_conn = pg_connect("localhost", "5432", "", "", $database); if (!$db_conn): ?> <b>无法连上 <? echo $database ?> 数据库</b><?php exit; endif;
$qu = pg_exec ($db_conn, "SELECT * FROM verlag ORDER BY autor"); $row = 0;
while ($data = pg_fetch_object ($qu, $row)): echo $data->autor." ("; echo $data->jahr ."): "; echo $data->titel."<BR>"; $row++; endwhile; ?>
<pre><?php $fields[] = Array("autor", "Author"); $fields[] = Array("jahr", " Year"); $fields[] = Array("titel", " Title"); $row = 0; while ($data = pg_fetch_object($qu, $row)): echo "<hr><p>\n"; reset ($fields); while (list (,$item) = each($fields)): echo $item[1].": ".$data->$item[0]."\n"; endwhile; $row++; endwhile; echo "<p><hr>"; ?> </pre><?php pg_freeResult($qu); pg_close($db_conn); ?>
整理: sadly (www.phpx.com)
|