If your PHP application uses mysql service then you need to perform
additional steps to use MySQL service
1)Create mysql instance using the below command
cf create-service mysql 100 mysql-12345
2) bind the servicee instance to an application
cf bind-service cbdb mysql-12345
3) Push the application again using 'cf push' to ensure your
env variable changes take effect
When you complete above step of binding the serive, you can
find the VCAP_SERVICES environment variable the data that is required by the
application to communicate with the service instance.
4)You can see the VCAPSERVICE env using the below cf
command. In below command cbdb is my application name
cf files cbdb logs/env.log
5) The VCAP_SERVICES environment variable includes
information, such as the following items, that the sample PHP application can
use to connect to the MySQL service instance:-
VCAP_SERVICES={"mysql-5.5":[{"name":"mysql-12345","label":"mysql-5.5","tags":["m
ysql","relational","data_management","ibm_experimental"],"plan":"100","credentia
ls":{"name":"db9296b41fb8f870b9614f05b156a","hostname":"198.11.234.66","host
":"198.11.234.66","port":3307,"user":"uWI3jalvsPBpA","username":"uWI3jalvsPBpA",
"password":"pCAeQjBVVGw","uri":"mysql://uWI3jalvsPB:pCAeQjBVoeVGw@198.11.234
.66:3307/db9296b41fb8841bf870b14f05b156a"}}]}
Demonstrate how the PHP sample application uses the VCAP_SERVICES
environment variable information
$db =
$vcap_services->{'mysql-5.5'}[0]->credentials;
$mysql_database
= $db->name;$mysql_port=$db->port;
$mysql_host=$db->host;
$mysql_server_name =$db->host . ':' . $db->port;
$mysql_username = $db->username;
$mysql_password = $db->password;
'db'=>array(
'connectionString' => 'mysql:host='.$mysql_host.';port='.$mysql_port.';dbname='.$mysql_database,
'emulatePrepare' => true,
'username' => $mysql_username,
'password' => $mysql_password,
'charset' => 'utf8',
),
No comments:
Post a Comment