daily pastebin goal
78%
SHARE
TWEET

test

dave3460 Feb 13th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. $servername = "localhost";
  3. $username = "user";
  4. $password = "pass";
  5.  
  6. try {
  7.     $conn = new PDO("mysql:host=$servername;dbname=dbname", $username, $password);
  8.     // set the PDO error mode to exception
  9.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  10.     echo "Connected successfully";
  11.     }
  12. catch(PDOException $e)
  13.     {
  14.     echo "Connection failed: " . $e->getMessage();
  15.     }
  16.  
  17.  
  18.  
  19. /* VARIABLES */
  20.  
  21.  
  22. $url = 'My url i use'; // Change this to the correct URL to access the data
  23.  
  24. $display_output = 1; // Change this to 1 if you want to run this in the browser and see the output. Or if you want the cron job to email you the output so that you know it is working.
  25.  
  26. $display_queries = 1; // Change this to 1 if you want to see the SQL equivalent statements in the browser, of what is being run.
  27.  
  28. $live = 1; // Change this to 1 once you have set up the table in the database and you want the script to run properly and update your DB, rather than just showing you the text output
  29.  
  30.  
  31.  
  32.  
  33. // This is storing the output of that page into the variable "$data"
  34.  
  35. $data = file_get_contents($url);
  36.  
  37.  
  38. // This line is getting rid of the first 2 characters in the data, ie: the "1 "
  39.  
  40. $data = substr($data, 2);
  41.  
  42. // This line is adding an extra "@" to the end of the data to fix a small problem
  43.  
  44. $data = $data . '@';
  45.  
  46. // This is converting all new line characters into line break tags
  47.  
  48. $data = nl2br($data);
  49.  
  50. // This is replacing all line break tags with "^"
  51.  
  52. $data = preg_replace("/\<br \/\>/", "^", $data);
  53.  
  54.  
  55.  
  56.  
  57. $output = '';
  58.  
  59. $output .= '<h1 style="text-align:center;">Cron Output</h1><br><hr><br>';
  60.  
  61. echo '<p style="text-align:center;font-size:10pt;color:red;">If you are viewing this page in the browser, you will need to check the source code on the server to see what is happening and what you need to do.</p>';
  62.  
  63.  
  64. // Start over again with the new String of data, this time explode with "^" so we can get each defence slot
  65.  
  66. $slots = explode("^", $data);
  67.  
  68. $output .= 'defence Slots: ' . count($slots) . '<br><br>';
  69.  
  70. // Explode to get number of elements as well
  71.  
  72. $el = explode("@", $data);
  73.  
  74. $output .= '<br><br>';
  75.  
  76. if($live == 1)
  77. {
  78. // Truncate the table to remove all current rows
  79. mysql_query("TRUNCATE TABLE `_defence`") or die('Error: ' . mysql_error());
  80. }
  81.  
  82.  
  83. $query = '';
  84.  
  85.  
  86.  
  87. // Loop through each attck slot
  88.  
  89. for($i = 0; $i < count($slots); $i++)
  90. {
  91.  
  92. $slots[$i] = trim($slots[$i]);
  93.  
  94. if($slots[$i] != '@')
  95. { # Not Just "@"
  96.  
  97.  
  98. $liveQuery = '';
  99.  
  100. // Update query String if output is desired
  101.  
  102. $query .= "<br><br>INSERT INTO `_defence` (`playersname`, `playerslevel`, `playersexp`,  `lastupdated`) VALUES (";
  103.  
  104. // Live Query String
  105.  
  106. $liveQuery .= "INSERT INTO `_defence` (`playersname`, `playerslevel`, `playersexp`,  `lastupdated`) VALUES (";
  107.  
  108.  
  109.  
  110.  
  111.  
  112. $output .= '<u>Slot '.$i.'</u><br>';
  113.  
  114. // Explode this defence slot with "@" to get each element
  115.  
  116. $elements = explode("@", $slots[$i]);
  117.  
  118. // Loop through them
  119.  
  120. for($j = 0; $j < count($elements); $j++)
  121. {
  122.  
  123. $query .= "'".$elements[$j]."'";
  124. $liveQuery .= "'".$elements[$j]."'";
  125.  
  126. if($j < (count($elements) - 1))
  127. {
  128. $query .= ',';
  129. $liveQuery .= ',';
  130. }
  131.  
  132. $output .= '['.$j.']: '.$elements[$j].'<br>';
  133. }
  134.  
  135. $output .= '<br><br>';
  136.  
  137. $now = date('d.m.Y - H:i:s');
  138.  
  139. $query .= ", '".$now."');";
  140. $liveQuery .= ", '".$now."')";
  141.  
  142.  
  143. // If script is live, insert into the DB
  144. if($live == 1)
  145. {
  146. mysql_query($liveQuery) or die('Error (Cannot Insert defenceid ['.$i.']) Query =><br><br>'.$liveQuery.' : ' . '<br><br>' . mysql_error());
  147. }
  148.  
  149. } # Not Just "@"
  150.  
  151. }
  152.  
  153. if($display_output == 1)
  154. {
  155. echo '<br><hr><br>';
  156. echo $output;
  157. }
  158. if($display_queries == 1)
  159. {
  160. echo '<br><hr><br>';
  161. echo $query;
  162. }
  163. if($live == 1)
  164. {
  165. echo '<p style="text-align:center;font-size:10pt;color:blue;">Database Updated Successfully</p>';
  166. }
RAW Paste Data
Top