Guest User

Untitled

a guest
Aug 7th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "AWS";
  7.  
  8. $link = mysqli_connect($servername,$username,$password,$dbname);
  9.  
  10. if (!$link) {
  11. echo "Error: Unable to connect to MySQL." . PHP_EOL;
  12. echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
  13. echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
  14. exit;
  15. }
  16. $regions_str = '{
  17. "Regions": [
  18. {
  19. "Endpoint": "ec2.ap-south-1.amazonaws.com",
  20. "RegionName": "ap-south-1"
  21. },
  22. {
  23. "Endpoint": "ec2.eu-west-1.amazonaws.com",
  24. "RegionName": "eu-west-1"
  25. },
  26. {
  27. "Endpoint": "ec2.ap-southeast-1.amazonaws.com",
  28. "RegionName": "ap-southeast-1"
  29. },
  30. {
  31. "Endpoint": "ec2.ap-southeast-2.amazonaws.com",
  32. "RegionName": "ap-southeast-2"
  33. },
  34. {
  35. "Endpoint": "ec2.eu-central-1.amazonaws.com",
  36. "RegionName": "eu-central-1"
  37. },
  38. {
  39. "Endpoint": "ec2.ap-northeast-2.amazonaws.com",
  40. "RegionName": "ap-northeast-2"
  41. },
  42. {
  43. "Endpoint": "ec2.ap-northeast-1.amazonaws.com",
  44. "RegionName": "ap-northeast-1"
  45. },
  46. {
  47. "Endpoint": "ec2.us-east-1.amazonaws.com",
  48. "RegionName": "us-east-1"
  49. },
  50. {
  51. "Endpoint": "ec2.sa-east-1.amazonaws.com",
  52. "RegionName": "sa-east-1"
  53. },
  54. {
  55. "Endpoint": "ec2.us-west-1.amazonaws.com",
  56. "RegionName": "us-west-1"
  57. },
  58. {
  59. "Endpoint": "ec2.us-west-1.amazonaws.com",
  60. "RegionName": "us-west-1"
  61. },
  62. {
  63. "Endpoint": "ec2.us-west-2.amazonaws.com",
  64. "RegionName": "us-west-2"
  65. }
  66. ]
  67. }';
  68. $json_a=json_decode($regions_str,true);
  69.  
  70. foreach($json_a['Regions'] as $mydata)
  71.  
  72. $end_point = $mydata["Endpoint"];
  73. $region_name = $mydata["RegionName"];
  74. $ac_id = 1;
  75. {
  76. $statement = $link->prepare("INSERT INTO `aws_regions`(`ac_id`, `name`,`endpoint`) VALUES(?, ?, ?)");
  77.  
  78. $statement->bind_param("iss",1,$mydata['Endpoint'], $mydata['RegionName']);
  79. $statement->execute();
  80. }
  81. mysqli_close($link);
  82. ?>
Add Comment
Please, Sign In to add comment