Bluemix-将dashDB连接到PHP应用程序
我看到了这篇非常有用的文章,并尝试按照它概述的步骤进行操作。然而,我是新手,所以我想我可能在某个地方搞砸了 我尝试在网页上定制代码,该网页是为了让某人登录到我的情况而创建的 我正在制作日历,所以我需要这个数据库。主要目标:在Bluemix中创建类似日历的web应用程序,并将数据库服务绑定到该应用程序,以便存储事件 以下是我采取的步骤:Bluemix-将dashDB连接到PHP应用程序,php,ibm-cloud,dashdb,Php,Ibm Cloud,Dashdb,我看到了这篇非常有用的文章,并尝试按照它概述的步骤进行操作。然而,我是新手,所以我想我可能在某个地方搞砸了 我尝试在网页上定制代码,该网页是为了让某人登录到我的情况而创建的 我正在制作日历,所以我需要这个数据库。主要目标:在Bluemix中创建类似日历的web应用程序,并将数据库服务绑定到该应用程序,以便存储事件 以下是我采取的步骤: 使用PHP、HTML和CSS创建网站 绑定服务(dashDB)并通过上载一个.csv文件放入表中,该文件有两列,一列标记为用户名,另一列标记为密码。有两个记录,(
<?php
if( getenv("VCAP_SERVICES") ) {
$json = getenv("VCAP_SERVICES");
}
// No DB credentials
else {
throw new Exception("No Database Information Available.", 1);
}
// Decode JSON and gather DB Info
$services_json = json_decode($json,true);
$bludb_config = $services_json["dashDB"][0]["credentials"];
// Create DB connect string
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=".
$bludb_config["db"].
";HOSTNAME=".
$bludb_config["host"].
";PORT=".
$bludb_config["port"].
";PROTOCOL=TCPIP;UID=".
$bludb_config["username"].
";PWD=".
$bludb_config["password"].
";";
?>
您需要确保CF应用程序包含用于PHP的dashDB/DB2驱动程序。将此附加到cf push命令可以修复它,
-b您需要安装db2包驱动程序 如果已安装Cloud Foundry,请运行此命令:cf push-b 或 将buildpack选项添加到manifest.yml文件[manifest.yml]
Buildpack:请发布cf日志HybridCloudEventsTest的输出——最近虽然此链接可能会回答此问题,但堆栈溢出时不鼓励使用仅链接的答案,您可以通过获取链接的重要部分并将其放入答案中来改进此答案,如果链接被更改或删除,这将确保您的答案仍然是答案:)
<html>
<head>
<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<?php
//Include DB conexion
require('includes/ConexionDB.php');
$tbl_name="SCHEMA.USERNAMEFILE"; // Table name
// username and password sent from form
$myusername="Jessica";
$mypassword="Fish";
// Connect to BLUDB
$conn = db2_connect($conn_string, '', '');
if ($conn) {
// Prepare, execute SQL and iterate through resultset
$sql="SELECT count(*) FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$stmt = db2_prepare($conn, $sql);
$result = db2_execute($stmt);
echo $result;
?>
</body>
</html>
In file included from /tmp/staged/app/clidriver/include/sqlcli1.h:45:0,
from /tmp/pear/temp/ibm_db2/php_ibm_db2.h:37,
from /tmp/pear/temp/ibm_db2/ibm_db2.c:34:
/tmp/staged/app/clidriver/include/sqlcli.h:870:0: warning: "ODBCVER" redefined [
enabled by default]
^
In file included from /app/php/include/php/TSRM/tsrm_config.h:1:0,
from /app/php/include/php/TSRM/tsrm_config_common.h:13,
from /app/php/include/php/TSRM/tsrm_virtual_cwd.h:27,
from /app/php/include/php/main/php.h:401,
from /tmp/pear/temp/ibm_db2/ibm_db2.c:30:
/app/php/include/php/main/../main/php_config.h:2095:0: note: this is the location of the previous definition
#define ODBCVER 0x0300
/tmp/pear/temp/ibm_db2/ibm_db2.c:1299:32: warning: cast to pointer from integer
of different size [-Wint-to-pointer-cast]
^
/tmp/pear/temp/ibm_db2/ibm_db2.c:1308:32: warning: cast to pointer from integer
of different size [-Wint-to-pointer-cast]
SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)vParam, /* was (SQLPOINTER)&vParam */
SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)vParam,
^
/tmp/pear/temp/ibm_db2/ibm_db2.c:1328:32: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)vParam, /* was (SQLPOINTER)&vParam */
^
/tmp/pear/temp/ibm_db2/ibm_db2.c:1357:37: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
SQL_ATTR_ROWCOUNT_PREFETCH, (SQLPOINTER)vParam,
^
/tmp/pear/temp/ibm_db2/ibm_db2.c:1495:89: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
rc = SQLSetConnectAttr((SQLHDBC)((conn_handle*)handle)->hdbc, SQL_ATTR_AUT
OCOMMIT, (SQLPOINTER)pvParam, SQL_IS_INTEGER);
^
----------------------------------------------------------------------
/tmp/pear/temp/pear-build-vcaph4uzHz/ibm_db2-1.9.9/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Libraries have been installed in:
Build complete.
Don't forget to run 'make test'.
requested state: started
instances: 1/1
usage: 128M x 1 instances
urls: hybridcloudeventstest.mybluemix.net
last uploaded: Tue Jun 28 18:20:09 UTC 2016
stack: unknown
buildpack: https://github.com/ibmdb/db2heroku-buildpack-php
state since cpu memory disk deta
ils
#0 running 2016-06-28 02:21:50 PM 0.0% 67M of 128M 178.1M of 1G