如何从我的网站访问基于 LAN 的 postgresql 数据库

发布于 2024-12-06 20:04:20 字数 177 浏览 0 评论 0原文

我们有基于 LAN 的 .Net 应用程序和 Postgresql 8.1 ,现在我的任务是在网站上提供接口来读取和写入基于 LAN 的数据库上的两个表,我不知道从哪里开始请帮助我解决这个问题。

局域网:Windows NT 2003 。网 Postgresql 8.1

网站: PHP 5.3 mysql

We have lan based .Net application with Postgresql 8.1 , now i have task to provide interface on website to read and write two tables on LAN based database I don't know where to start Please help me to solve this problem.

Lan: Windows NT 2003
.Net
Postgresql 8.1

Website:
PHP 5.3
Mysql

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑色毁心梦 2024-12-13 20:04:20

您需要在 Postgres 上启用远程连接。但要警惕安全隐患。

还没读完,但是这个应该可以让您了解在服务器上采取的步骤。对于连接器,通常只需将连接功能指向远程IP即可。

You need to enable remote connections on Postgres. But be wary of security implications.

Haven't read it all, but this should give you an idea on the steps to take on the server. For the connector, you generally just need to point the connect function at the remote IP.

扮仙女 2024-12-13 20:04:20

这是如何做到这一点的。复制自此处

 <?php
// Connecting, selecting database
$dbconn = pg_connect("host=localhost dbname=publishing user=www password=foo")
    or die('Could not connect: ' . pg_last_error());

// Performing SQL query
$query = 'SELECT * FROM authors';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());

// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);
?>

在上面的代码中,替换 localhostPostgres 主机的 IP 地址

Here is how to do the trick. Copied from here:

 <?php
// Connecting, selecting database
$dbconn = pg_connect("host=localhost dbname=publishing user=www password=foo")
    or die('Could not connect: ' . pg_last_error());

// Performing SQL query
$query = 'SELECT * FROM authors';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());

// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);
?>

in the above code, replace localhost by the IP-address of your Postgres host.

長街聽風 2024-12-13 20:04:20

在 Linux 上,需要修改两个文件以允许来自 localhost 之外的连接:
postgresql.conf,更改listen_addresses =“*”以接受来自任何地方的连接。然后向 pg_hba.conf 文件添加一行以允许从特定 IP 或网络访问数据库。如果您不担心安全性,输入:

host all all 192.168.1.0/24 trust

将允许 192.168.1.0/24 网络上的任何人访问任何数据库。显然这只能用于测试您是否可以访问数据库。将此限制为 Web 服务器 IP 地址并使用 md5,以便使用加密密码身份验证。

On Linux, two files need to be modified to allow connections other than from localhost:
postgresql.conf, change the listen_addresses = "*" to accept connections from anywhere. Then add a line to the pg_hba.conf file to allow access to the database from a particular IP or network. If you are not worried about security, entering:

host all all 192.168.1.0/24 trust

will allow anyone on the 192.168.1.0/24 network access to any database. Obviously this should only be used to test you can reach the database. Constrain this to the web servers IP address and use md5 so encrypted password authentication is used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文