【发布时间】:2020-01-22 03:44:43
【问题描述】:
代码有什么问题??
<?php
$host = "localhost";
$dbuser = "tesdb";
$dbpass = "123456";
$dbname = "tesdb";
// script koneksi php postgree
$dbcon = new PDO("pgsql:dbname=$dbname;host=$host", $dbuser, $dbpass);
//$query ="SELECT * FROM air_tanah.pembayaran";
$query ="select * from air_tanah.pembayaran";
$result = pg_query($dbcon, $query) or die('Query failed');
// output result
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo " Denda: " . $line['denda'] ." Penyimpan: " . $line['Penyimpan'] . "<br/>";
}
// free result
pg_free_result($result);
// close connection
pg_close($dbcon);
?>
这样的错误
警告:pg_query() 期望参数 1 是资源,在第 12 行的 C:\xampp\htdocs\grafig\read.php 中给出的对象 查询失败
【问题讨论】:
-
看来
$dbcon是一个实例而不是用于识别连接的数据库资源。请编辑您的问题并添加您为此变量分配值的代码。
标签: php postgresql