Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $servername = "localhost";
- $dbname = "_arealitydb";
- $username = "root";
- $password = "";
- $queryDebug = false;
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- function queryExec($query) {
- if ( $GLOBALS["queryDebug"])
- {
- echo $query + "<br>";
- }
- $conn = $GLOBALS["conn"];
- $sql = $query;
- $result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
- if (!$result)
- {
- die('Could not query:' . mysql_error());
- }
- return $result;
- }
- function getFirstCellValueFromQuery($query)
- {
- return queryExec($query) -> fetch_array()[0];
- }
- function printJsonFromQuery($query)
- {
- $result = queryExec($query);
- $rows = array();
- while($r = mysqli_fetch_assoc($result)) {
- $rows[] = $r;
- }
- print json_encode($rows);
- }
- if ( isset($_GET['queryToExecute']) ) {
- $query = $_GET['queryToExecute'];
- queryExec($query);
- }
Add Comment
Please, Sign In to add comment