简体   繁体   中英

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

I have to deploy a WebPage for illustrating sessions in PHP, but my app is not interacting with PostgreSQL Instance.

You can see here that the login and signup are not working.

Script

<?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";
}
?>

What could be the cause of this?

You need to debug your code and find your problem
pg_connect does not throw exception, so you have to translate to exception like below.

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();
}

Now you can look at the error and debug it easily

If issue is with deployment in cloud foundry; as a quick check see if you are using the FQDN for hostname? like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM