duannian4784 2013-04-02 02:07
浏览 35
已采纳

警告:pg_fetch_array():3不是有效的PostgreSQL结果资源

I'm trying to print out some records in a database to a table:

    session_start();
if(!isset($_SESSION['studentnum'])){
    echo "Please "."<a href='login.php'>login</a>";
    exit;
}

$host = "localhost";
$username = "xyz";
$password = "abc";
$database = "mno";
$port = "5432";

$dbh = pg_connect("host=".$host." port=".$port." dbname=".$database." user=".$username." password=".$password);
if (!$dbh){
    die("Error in connection: ".pg_last_error());
}
$studentnum = $_SESSION['studentnum'];


$sql = "select * from project.student s, project.courses c 
where s.student_num = c.student_num and s.student_num='".$studentnum."'";
$result = pg_query($sql) or die('Query failed: ' . pg_last_error());
pg_free_result($result);
pg_close($dbh);

and then

<?php
while ($line = pg_fetch_array($result)) {  <= this is line 52
    echo "\t<tr>
";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>
";
    }
    echo "\t</tr>
";
}
?>

but I'm getting this error:

 SCREAM: Error suppression ignored for
( ! ) Warning: pg_fetch_array(): 3 is not a valid PostgreSQL result resource in D:\wamp\wwwecords.php on line 52

What did I do wrong? I used this same code somewhere else and it worked, so I'm not sure what's missing here.

  • 写回答

1条回答 默认 最新

  • douji1999 2013-04-02 03:06
    关注

    I figured it out. I accidentally called pg_free_result($result); before using $result

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?