Advertisement
Guest User

Untitled

a guest
Jun 21st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?php
  2. $DBhost="localhost";
  3. $DBuser="userid"; These are set properly
  4. $DBpassword="password"; These are set properly
  5.  
  6. try {
  7. # MySQL with PDO_MYSQL
  8. $conn = new PDO("mysql:host=$DBhost; charset=utf8", $DBuser, $DBpassword);
  9. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  10. $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);}
  11. catch(PDOException $e) {
  12. echo $e->getMessage();
  13. }
  14.  
  15. try {
  16. echo "size of sql = " . sizeof($sql) . "<br />";
  17. $conn->beginTransaction();
  18. for($i=0; $i<sizeof($sql); $i++){
  19. $stmt = $conn->prepare($sql[$i]);
  20. $stmt->execute($sql[$i]);
  21. echo "executing " . $sql[$i] . "<br />rn";
  22. }
  23. $conn->commit();
  24. $message = "Player successfully updated !!";
  25. $json = array('status' => 'success', 'message' => $message);
  26. $json_data = json_encode($json);
  27. echo $json_data;
  28. return;
  29.  
  30. } catch (PDOException $e) {
  31. $conn->rollback();
  32. $message = "Could not process transaction. Error:" . $e->getMessage();
  33. $json = array('status' => 'failure', 'message' => $message);
  34. $json_data = json_encode($json);
  35. echo $json_data;
  36. return;
  37. }
  38.  
  39. size of sql = 7
  40. executing INSERT INTO bowlingt_lg_shared.player_changes (change_date, change_text) VALUES ('2016-06-21', 'Player ID # 1812(Brady Jr., Tom - LB - MIN) name had changed from Brady Jr., Tom to Brady, Tom')
  41. executing INSERT INTO bowlingt_lg_shared.player_changes (change_date, change_text) VALUES ('2016-06-21', 'Player ID # 1812(Brady Jr., Tom - LB - MIN) tm_id had changed from 9022 to 9003')
  42. executing INSERT INTO bowlingt_lg_shared.player_changes (change_date, change_text) VALUES ('2016-06-21', 'Player ID # 1812(Brady Jr., Tom - LB - MIN) pos had changed from LB to QB')
  43. executing INSERT INTO bowlingt_lg_shared.player_changes (change_date, change_text) VALUES ('2016-06-21', Player ID # 1812 (Brady Jr., Tom - LB - MIN) has changed eligible positions from QB, R, LB, DEF to QB, RB, R, K)
  44. executing INSERT INTO bowlingt_lg_shared.player_changes (change_date, change_text) VALUES ('2016-06-21', 'Player ID # 1812(Brady Jr., Tom - LB - MIN) active had changed from 0 to 1')
  45. executing INSERT INTO bowlingt_lg_shared.player_changes (change_date, change_text) VALUES ('2016-06-21', 'Player ID # 1812(Brady Jr., Tom - LB - MIN) tm_abbr had changed from MIN to NE')
  46. executing UPDATE bowlingt_lg_shared.players SET Name = 'Brady, Tom', tm_id = 9003, pos = 'QB', elig_pos = 'QB, RB, R, K', active = 1 WHERE id = 1812
  47. {"status":"success","message":"Player successfully updated !!"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement