我创建了一个Php文件,它从Postgres数据库中获取数据,但是当我运行该文件时,它不会显示数据库表中存在的内容(记录)。
我也使用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>
答案 0 :(得分:0)
雅想出怎么做。 以下是守则。
<!DOCTYPE html>
<html>
<head>WELCOME</head>
<body style="background-color:#E4E5E7">
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
table#t01 {
width: 100%;
background-color: #f1f1c1;
}
</style>
</head>
<body>
<?php
$url= 'http://yoururltypehere.com';
$options = array(
'http' => array(
'header' => array(
'name: '.$_GET['name'],
),
'method' => 'GET',
),
);
$context = stream_context_create($options);
$output = file_get_contents($url, false,$context);
$arr = json_decode($output,true);
?>
<table style="width:100%">
<tr>
<th>ID</th>
<th>NAME</th>
<th>PHONE_NO</th>
<th>STATUS</th>
</tr>
<br>
<?php
for($x=0;$x<count($arr);$x++)
{
?>
<tr>
<td><?php echo $arr[$x]['id']; ?>
<td><?php echo $arr[$x]['name']; ?>
<td><?php echo $arr[$x]['ph_no']; ?>
<td><?php echo $arr[$x]['stats']; ?>
</tr>
<?php
}
?>
<br>
</table>
</body>
</html>