I have seen this very helpful post Questions and tried to follow the steps it outlined. However I am new to this so I think I may have messed up somewhere.
I tried to tailor the code on the webpage which was created to log someone in to my situation.
I am making a calendar so that is why I need this database. Main Goal: make calendar-like web application in Bluemix and bind a database service to it so that I can store events.
These are the steps I took:
- created a website with PHP, HTML, and CSS
- Bound the service (dashDB) and put in a table by uploading a .csv file that had two columns, one labeled usernames and the other passwords. There were two records, (Jessica - Fish, Tom - Bear) It is called USERNAMEFILE
- included a php file which would connect to the database called ConexionDB.php
- 'required' the ConexionDB.php file in the php file called index.php where I try to access the database. When trying to access the database I was just trying to see if I could. It currently serves no purpose other than to print out the number 1.
However when I do all this and then push my project out with this command "cf push HybridCloudEventsTest -b GitHub and then go to my website I get that the page isn't working err code 500. I can also put what happened in my cmd line if that helps. I also posed my code below too with the titles of each file. I did not include all of my index.php file since it worked prior to me putting in the database code so I believe that is where the problem lies. If you need my index and css code I can post it as well. Any help is appreciated
ConexionDB.php
<?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"].
";";
?>
index.php
<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>
cf log (I could not fit it all here but let me know if you need other lines or if there is some other way for me to show it to you)
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