我正在使用此 php 来测试我是否已连接到 postgree 数据库,效果很好,但我如何插入错误消息以及显示数据库已连接和未连接的消息?
例子: 喜欢:你正在连接到:database_name
或:
您无法连接到:database_name
这是我的代码:
<?php
$connection = pg_connect ("host=localhost dbname=site user=postgres password=root");
?>
最佳答案
只需测试连接的真实性:
<?php
$connection = pg_connect ("host=localhost dbname=site user=postgres password=root");
if($connection) {
echo 'connected';
} else {
echo 'there has been an error connecting';
}
?>
关于php - 使用 postgresql 数据库的简单测试 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32700618/