我怎样才能编写以下php但使用postgresql函数而不是mysql?
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
如果我无法连接到数据库,则输出错误。我会使用pg_result_error
功能吗?
我相信它看起来像下面。如果我错了,请纠正我。将尽快测试验证。
if (pg_result_error_field($con))
{
echo "Failed to connect to PostgreSQL: " . pg_result_error_field();
}
由于该字段不存在时此函数的返回值为NULL,或者失败时返回FALSE。以上代码应该有效,并且只有在pg_result_error_field
函数返回值时才回显失败的响应。
文档:http://php.net/manual/en/function.pg-result-error-field.php