【发布时间】: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()”