Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用Php从postgress数据库检索数据?_Php_Postgresql_Server_Record - Fatal编程技术网

无法使用Php从postgress数据库检索数据?

无法使用Php从postgress数据库检索数据?,php,postgresql,server,record,Php,Postgresql,Server,Record,我创建了一个Php文件,它从Postgres数据库中获取数据,但是当我运行该文件时,它不会显示数据库表中的内容(记录) 我还使用Apache服务器和Python SimpleHTTPServer运行了这个程序 我也重新启动了Postgres服务器 以下是该文件的代码: index.php 网页 数据库信息 你知道怎么做了。 下面是代码 <!DOCTYPE html> <html> <head>WELCOME</head> <body s

我创建了一个Php文件,它从Postgres数据库中获取数据,但是当我运行该文件时,它不会显示数据库表中的内容(记录)

我还使用Apache服务器和Python SimpleHTTPServer运行了这个程序

我也重新启动了Postgres服务器

以下是该文件的代码:

index.php


网页
数据库信息
你知道怎么做了。 下面是代码

<!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>

欢迎
表,th,td{
边框:1px纯黑;
边界塌陷:塌陷;
}
th,td{
填充物:5px;
文本对齐:左对齐;
}
表t01{
宽度:100%;
背景色:#F1C1;
}
身份证件
名称
电话号码
地位



它可能有助于
打印(con)紧跟在
pg_connect()
之后,然后
打印(rs)
pg_query()
之后,因此更明显的是您是否实际连接并执行了查询,而不是您的表是空的。连接之前的echo命令似乎不起作用,因此它不是postgres错误。你会得到一个500,打开调试,看看是什么错误。@anton samsonov我已经做了,但它没有显示任何Jakub建议的内容,请检查你的Web服务器的错误日志-PHP会在那里转储所有重要的消息。
<!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>