i have been following tutorial: "build , deploy rest api on ibm bluemix php , mysql."
the tutorial uses mysql. want use sql database service, uses db2, think. tutorial implements rest api. when try making rest call using these links nothing in return.
for example, here's how use bluemix application's rest api:
- http://products-api-db2-test2-5.mybluemix.net/v1/products.json
- http://products-api-db2-test2-5.mybluemix.net/v1/products
i have downloaded source code link below , edited manifest.yml
give unique name , host. have attempted edit index.php
connect sql database service opposed mysql database service.
my code repository here: vvaswani | products-api.
after uploading source bluemix, create table in database using following query:
create table products ( id int, name varchar(5), price decimal(5,2) );
i populate database with following query:
insert products (id, name, price) values (1, 'garden spade', 15.99), (2, 'cotton hammock', 54.50), (3, 'single airbed', 35.49);
i bind database app uploaded (which source code tutorial). said above, when try accessing rest endpoint,s blank page. think should seeing json in web browser. think there wrong connection between app , database.
in index.php
file, there section specifying connection mysql database.
// mysql service configuration bluemix $services = getenv("vcap_services"); $services_json = json_decode($services, true); $mysql_config = $services_json["mysql-5.5"][0]["credentials"]; $db = $mysql_config["name"]; $host = $mysql_config["host"]; $port = $mysql_config["port"]; $username = $mysql_config["user"]; $password = $mysql_config["password"]; // initialize eloquent orm $capsule = new capsule; // use bluemix development $capsule->addconnection(array( 'driver' => 'mysql', 'host' => $host, 'port' => $port, 'database' => $db, 'username' => $username, 'password' => $password, 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '' ));
i think need edit not sure how to. have tried few things. example changing $services_json["mysql-5.5"][0]
$services_json["sqldb"][0]
. tried changing driver driver' => 'mysql'
'driver' => 'sqldb'
.
i think credentials important here are. mysql credentials:
{ "mysql-5.5": [ { "name": "mysql-338", "label": "mysql-5.5", "plan": "100", "credentials": { "name": "d80979f54940b447ab178d6b2ea42a7f6", "hostname": "198.11.234.66", "host": "198.11.234.66", "port": 3307, "user": "uyhdjpnyxi357", "username": "uyhdjpnyxi357", "password": "xxxxxxxx", "uri": "mysql://uyhdjpnyxi357:pzofbeiig0i16@198.11.234.66:3307/d80979f54940b447ab178d6b2ea42a7f6" } } ] }
sql database credentials:
{ "sqldb": [ { "name": "sql database-78", "label": "sqldb", "plan": "sqldb_free", "credentials": { "port": 50000, "db": "sqldb", "username": "user04128", "host": "75.126.155.153", "hostname": "75.126.155.153", "jdbcurl": "jdbc:db2://75.126.155.153:50000/sqldb", "uri": "db2://user04128:daxopnuhtj6g@75.126.155.153:50000/sqldb", "password": "xxxxxxxx" } } ] }
it seems mysql database credentials have name attribute used in index reference database. sql database credentials have db property. might try playing around in meantime.
sorry long post. of new me.
cheers.
if want run on bluemix (via cloud foundry) need php buildpack db2 driver support. 1 should work: https://github.com/ibmdb/db2heroku-buildpack-php.
working sample here:
tip: troubleshoot problems try cf logs "app_name" --recent
command. read more here
Comments
Post a Comment