0
我已經創建了一個Php文件,它從Postgres數據庫中獲取數據,但是當我運行該文件時,它不顯示數據庫表中存在的內容(記錄)。無法使用Php從postgress數據庫中檢索數據?
我使用Apache服務器和Python SimpleHTTPServer也運行此。
我也重新啓動了Postgres服務器。
下面是該文件的代碼:
的index.php
<!DOCTYPE html>
<html>
<head>
<title>
webpage
</title>
</head>
<body>
<h1>
INFORMATION OF DATABASE
</h1>
<?php
$host = "localhost";
$user = "myappuser";
$pass = "password";
$db = "myapp";
echo "\n test";
$con = pg_connect("host=$host dbname=$db user=$user password=$pass")
or die ("Could not connect to server\n");
$query = "SELECT * FROM app1_snippet";
$rs = pg_query($con, $query) or die("Cannot execute query: $query\n");
while ($row = pg_fetch_assoc($rs)) {
echo $row['id'] . " " . $row['name'] . " " . $row['phone_no']. " " . $row['status'];
echo "\n";
}
pg_close($con);
?>
</body>
</html>
它可以幫助'的print_r(CON); pg_connect後''權()'然後'的print_r(RS);'pg_query後'()'所以它變得更加明顯,你是否已經實際連接和執行查詢而不是你的表是空的。 –
甚至連接之前的echo命令似乎不起作用,因此它不是postgres錯誤。你得到一個500,打開調試,看看有什麼錯誤。 –
@anton samsonov我已經這樣做,但它沒有顯示任何東西 –