Guest User

Untitled

a guest
Nov 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. $servername = "localhost";
  2. $dbname = "_arealitydb";
  3. $username = "root";
  4. $password = "";
  5. $queryDebug = false;
  6.  
  7. // Create connection
  8. $conn = mysqli_connect($servername, $username, $password, $dbname);
  9. // Check connection
  10. if (!$conn) {
  11. die("Connection failed: " . mysqli_connect_error());
  12. }
  13.  
  14. function queryExec($query) {
  15. if ( $GLOBALS["queryDebug"])
  16. {
  17. echo $query + "<br>";
  18. }
  19.  
  20. $conn = $GLOBALS["conn"];
  21.  
  22. $sql = $query;
  23. $result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
  24.  
  25. if (!$result)
  26. {
  27. die('Could not query:' . mysql_error());
  28. }
  29.  
  30. return $result;
  31. }
  32.  
  33. function getFirstCellValueFromQuery($query)
  34. {
  35. return queryExec($query) -> fetch_array()[0];
  36. }
  37. function printJsonFromQuery($query)
  38. {
  39. $result = queryExec($query);
  40.  
  41. $rows = array();
  42. while($r = mysqli_fetch_assoc($result)) {
  43. $rows[] = $r;
  44. }
  45. print json_encode($rows);
  46. }
  47.  
  48. if ( isset($_GET['queryToExecute']) ) {
  49. $query = $_GET['queryToExecute'];
  50. queryExec($query);
  51. }
Add Comment
Please, Sign In to add comment