簡體   English   中英

無法在我的 IBM CLoud 中的 PHP Cloud Foundry 應用程序和 Postgre SQL 之間建立連接

[英]Unable to establish connection between PHP Cloud Foundry app and Postgre SQL in my IBM CLoud

我必須部署一個網頁來說明 PHP 中的會話,但我的應用程序沒有與 PostgreSQL 實例交互。

您可以在此處看到登錄和注冊不起作用。

腳本

<?php
/* Attempt to connect to MySQL database */
$user = 'admin';
$password = 'adminpassword';
$hostname = 'hostname';
$port = 50000;
$database = 'ibmclouddb';

$conn = pg_connect("host=$hostname port=$port dbname=$database user=$user password=$password sslmode=verify-full sslcert=../6be25d73-0600-11ea-9bce-eaebe975ceba");

// Check connection
if ($conn === false) {
    die("ERROR: Could not connect. " );
    echo "Con't Connect";
}
?>

這可能是什么原因?

你需要調試你的代碼並找到你的問題
pg_connect不會拋出異常,因此您必須轉換為如下所示的異常。

function exception_error_handler($errno, $errstr, $errfile, $errline ) {
    throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");

try {
    $conn=@pg_connect("host=dbhost user=dbuser dbname=db password=dbpass");
} Catch (Exception $e) {
    echo $e->getMessage();
}

現在您可以查看錯誤並輕松調試它

如果雲代工廠中的部署存在問題; 快速檢查一下您是否使用 FQDN 作為主機名? 喜歡

$hostname = 'hostname.abc.server.net';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM