Guest User

Untitled

a guest
Apr 9th, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <?php
  2.  
  3. if(!$_ENV["VCAP_SERVICES"]){ //local dev
  4. $mysql_server_name = "127.0.0.1:3306";
  5. $mysql_username = "root";
  6. $mysql_password = "";
  7. $mysql_database = "test";
  8. } else { //running in Bluemix
  9. $vcap_services = json_decode($_ENV["VCAP_SERVICES" ]);
  10. if($vcap_services->{'mysql-5.5'}){ //if "mysql" db service is bound to this application
  11. $db = $vcap_services->{'mysql-5.5'}[0]->credentials;
  12. }
  13. else if($vcap_services->{'cleardb'}){ //if cleardb mysql db service is bound to this application
  14. $db = $vcap_services->{'cleardb'}[0]->credentials;
  15. }
  16. else {
  17. echo "Error: No suitable MySQL database bound to the application. <br>";
  18. die();
  19. }
  20.  
  21. $mysql_database = $db->name;
  22. $mysql_port=$db->port;
  23. //$mysql_server_name ='${db->host}:${db->port}';
  24. $mysql_server_name =$db->host . ':' . $db->port;
  25. $mysql_username = $db->username;
  26. $mysql_password = $db->password;
  27.  
  28. //echo "Debug: " . $mysql_server_name . " " . $mysql_username . " " . $mysql_password . "\n";
  29. $mysqli = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database);
  30. if ($mysqli->connect_errno) {
  31. echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
  32. die();
  33. }
  34.  
  35. $mysqli->query(
  36. CREATE TABLE ACCESS_HISTORY (
  37. ID bigint(20) NOT NULL AUTO_INCREMENT,
  38. TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
  39. BROWSER varchar(64) DEFAULT NULL,
  40. IP_ADDRESS varchar(32) DEFAULT NULL,
  41. PRIMARY KEY (ID)
  42. ) ENGINE=NDB DEFAULT CHARSET=utf8
  43. );
  44.  
  45.  
  46. mysql_close();
  47. ?>
Add Comment
Please, Sign In to add comment