Guest User

Untitled

a guest
Jan 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', '1');
  5.  
  6.  
  7. //MySQL Connection
  8. mysql_connect("localhost", "***", "****") or
  9. die("Could not connect: " . mysql_error());
  10. mysql_select_db("wordpress");
  11.  
  12.  
  13. //Get API POST Action
  14. $action = '';
  15. if(isset($_POST['action']))
  16. {
  17. $action = $_POST['action'];
  18. }
  19.  
  20. //Execute Action
  21. switch ($action)
  22. {
  23. case 'getEvents':
  24. getEvents();
  25. break;
  26. default:
  27. echo "{failure:true}";
  28. break;
  29. }
  30.  
  31. function getEvents()
  32. {
  33. //Build Query
  34. $query = "SELECT id AS event_id, title AS event_title, start AS date FROM wp_aec_event";
  35. //Execute
  36. $result = mysql_query($query);
  37.  
  38. while($rec = mysql_fetch_array($result))
  39. {
  40. $arr[] = $rec;
  41. }
  42.  
  43. //JSON Convert
  44. $jsonresult = json_encode($arr);
  45.  
  46. //Print Result
  47. echo '{"success":"true","results":'.$jsonresult.'}';
  48. }
Add Comment
Please, Sign In to add comment