【问题标题】:Connecting to DashDB on Bluemix using Bluemix PHP App使用 Bluemix PHP 应用程序连接到 Bluemix 上的 DashDB
【发布时间】:2017-03-30 10:32:38
【问题描述】:

我无法使用 php 连接到 bluemix 上的 dashdb。我尝试了故障排除,我认为我的错误在函数 $conn = db2_connect( $conn_string, "", "" );

我需要在空的引号中输入什么值?请帮忙。

<!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>

【问题讨论】:

  • 你遇到了什么错误?
  • 根据php.net/manual/en/function.db2-connect.php,您询问的两个参数必须是空字符串。除了错误消息,你能分享你的 conn_string 是什么样的吗?在发布之前屏蔽 UID 和 PWD 的值。
  • DRIVER={IBM DB2 ODBC 驱动程序};DATABASE=BLUDB;HOSTNAME=dashdb-entry-*********-****.services.eu-gb.bluemix。网络;端口=50000;协议=TCPIP;UID=**********;密码=*************;
  • 从日志中,我得到这个错误:“调用未定义的函数 odbc_connect()”

标签: php ibm-cloud dashdb


【解决方案1】:

尝试用单引号替换双引号

$conn = db2_connect($conn_string, ' ', ' ' );

【讨论】:

  • 嗨 RiyaMRoy 我刚刚尝试过,但它也不起作用,我在日志中收到以下错误:“调用未定义函数 odbc_connect()”
  • 我觉得这个评论框的代码显示不好,请参考我最初的问题,它已经粘贴了整个页面的代码。谢谢
【解决方案2】:

我从 bluemix 支持部门获得了解决方案。 dashdb 驱动程序未正确安装。我在这里找到了驱动程序:https://github.com/ibmdb/db2heroku-buildpack-php

效果很好:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 2016-12-09
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    相关资源
    最近更新 更多