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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度