0
这里是我的我的.PHP的应用程序的代码连接到dashDB例如麻烦连接到dashDB上BlueMix
//parse VCAP_SERVICES Environment variable
$vcap_services = $_ENV["VCAP_SERVICES"];
$services_json = json_decode($vcap_services,true);
$sqldb = $services_json["dashDB"];
if (empty($sqldb)) {
echo "No sqldb service instance is bound. Please bind a sqldb service instance";
return;
}
//Get Credentials object (db,host,port,username,password)
$sqldb_config = $services_json["dashDB"][0]["credentials"];
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=".
$sqldb_config["db"].
";HOSTNAME=".
$sqldb_config["host"].
";PORT=".
$sqldb_config["port"].
";PROTOCOL=TCPIP;UID=".
$sqldb_config["username"].
";PWD=".
$sqldb_config["password"].
";";
$conn = db2_connect($conn_string, '', ''); //db connection
$sql = "SELECT * FROM BX1_USERS WHERE Username ='$username'";
$foundElements = 0;
if ($conn) {
$stmt = db2_exec($conn, $sql, array('cursor' => DB2_SCROLLABLE));
//lLINE 44 that the output.txt fiel referres to starts here
while ($row = db2_fetch_assoc($stmt)) {
$dbusername = $row['Username'];
$dbpassword = $row['Password'];
$dbfirstname = $row['FirstName'];
$dblastname = $row['LastName'];
$foundElements = 1;
}
}
print $foundElements;
echo "<br>";
print $sql;
echo "<br>";
if ($foundElements == 1){
/// rest of my code here
我测试数据库控制台打印$ SQL和它的作品就好了..但仍$ foundElements = 0 ...
我得到最近的日志文件,该错误:
“ PHP的警告:db2_fetch_assoc()预计参数1是资源,布尔在/ home/VCAP给出/第44行的app/www/login.php, “
我甚至已将此添加到代码:
print $sqldb_config["db"];
echo "<br>";
print $sqldb_config["host"];
echo "<br>";
print $sqldb_config["port"];
echo "<br>";
print $sqldb_config["username"];
echo "<br>";
print $sqldb_config["password"];
和页面显示完全相同的值作为我的VCAP。
我将此添加到我的代码: 如果(空($语句)){ 回声 “的声明为空”; } 和页面会回显该消息...所以$ stmt似乎是空的。有任何想法吗? –