使用 Bluemix PHP 应用连接到 Bluemix 上的 DashDB
Connecting to DashDB on Bluemix using Bluemix PHP App
我无法使用 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>
尝试用单引号替换双引号
$conn = db2_connect($conn_string, ' ', ' ' );
我从 bluemix 支持那里得到了解决方案。 dashdb driver 未正确安装。我在这里得到了 driver:https://github.com/ibmdb/db2heroku-buildpack-php
完美运行:)
我无法使用 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>
尝试用单引号替换双引号
$conn = db2_connect($conn_string, ' ', ' ' );
我从 bluemix 支持那里得到了解决方案。 dashdb driver 未正确安装。我在这里得到了 driver:https://github.com/ibmdb/db2heroku-buildpack-php
完美运行:)