Advertisement
Guest User

Untitled

a guest
Jun 18th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. //running in Bluemix
  2. $vcap_services = json_decode($_ENV["VCAP_SERVICES" ]);
  3. if(@$vcap_services->{'mysql-5.5'}){ //if "mysql" db service is bound to this application
  4. $db = $vcap_services->{'mysql-5.5'}[0]->credentials;
  5. }
  6. else if($vcap_services->{'cleardb'}){ //if cleardb mysql db service is bound to this application
  7. $db = $vcap_services->{'cleardb'}[0]->credentials;
  8. }
  9. else {
  10. echo "Error: No suitable MySQL database bound to the application. <br />";
  11. }
  12. $mysql_database = $db->name;
  13. $mysql_port=$db->port;
  14. $mysql_server_name =$db->hostname . ':' . $db->port;
  15. $mysql_username = $db->username;
  16. $mysql_password = $db->password;
  17.  
  18. $GLOBALS['sql'] = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database);
  19. if ($GLOBALS['sql']->connect_errno) {
  20. echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement