douqu2481
2017-03-30 10:32
浏览 46
已采纳

使用Bluemix PHP App连接到Bluemix上的DashDB

I'm failing to connect to the dashdb on bluemix using php. I tried troubleshooting and I think that my error is within the function $conn = db2_connect( $conn_string, "", "" );

What values do I need to put in the empty inverted commas? Please help.

<!DOCTYPE html>
<html>
<head>
<title>PHP Starter Application</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="style.css" />
</head>
<body>
<?php
    $usern = $_POST['un'];
    $passw = $_POST['pw'];
    if( getenv( "VCAP_SERVICES" ) )
    {
        # Get database details from the VCAP_SERVICES environment variable
        #
        # *This can only work if you have used the Bluemix dashboard to
        # create a connection from your dashDB service to your PHP App.
        #
        $details  = json_decode( getenv( "VCAP_SERVICES" ), true );
        $dsn      = $details [ "dashDB" ][0][ "credentials" ][ "dsn" ];
        //$ssl_dsn  = $details [ "dashDB" ][0][ "credentials" ][ "ssldsn" ];

        # Build the connection string
        #
        $driver = "DRIVER={IBM DB2 ODBC DRIVER};";
        $conn_string = $driver . $dsn;     # Non-SSL
        //$conn_string = $driver . $ssl_dsn; # SSL
            echo $conn_string;
        $conn = db2_connect( $conn_string, "", "" );
        //echo "<meta http-equiv='refresh' content='0; url=index.php'>";
        if( $conn )
        {
            echo "<p>Connection succeeded.</p>";
            db2_close( $conn );
        }
        else
        {
            echo "<p>Connection failed.</p>";
        }
    }
    else
    {
        //echo "<meta http-equiv='refresh' content='0; url=index.php'>";
        //echo "<p> <a href='index.php'>Missing DB Connection.</p>";
    }
?>
</body>
</html>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doufu3718 2017-05-02 08:15
    已采纳

    I got a solution from bluemix support. The dashdb driver was not properly installed. I got the driver here: https://github.com/ibmdb/db2heroku-buildpack-php

    It works perfectly :)

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题