我正在尝试将数据库中的某些记录打印到表格中:
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);
然后
<?php
while ($line = pg_fetch_array($result)) { <= this is line 52
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
?>
但是我收到了这个错误:
SCREAM: Error suppression ignored for
( ! ) Warning: pg_fetch_array(): 3 is not a valid PostgreSQL result resource in D:\wamp\www\records.php on line 52
我做错了什么?我在其他地方使用了相同的代码并且它有效,所以我不确定这里缺少什么。
答案 0 :(得分:0)
我明白了。在使用pg_free_result($result);
$result