Skip to content

Instantly share code, notes, and snippets.

@mduleone
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mduleone/9149ef34c86df55edfc7 to your computer and use it in GitHub Desktop.
Save mduleone/9149ef34c86df55edfc7 to your computer and use it in GitHub Desktop.
<?php
$db_params = new stdClass();
$db_params->host = "localhost";
$db_params->user = "Matt";
$db_params->pass = "";
$db_params->database = "parks";
$db_params->query = "SELECT * FROM currentQueue ORDER BY arrive ASC";
$db = mysqli_init();
$conn = $db->real_connect($db_params->host,
$db_params->user,
$db_params->pass,
$db_params->database);
if (!$conn) {
die("Failed to connect to MySQL: " . $db->error);
}
$query = $db->query($db_params->query);
if(!$query) {
return;
}
$results = array();
foreach ($query->fetch_all(MYSQLI_ASSOC) as $row) {
$rowArray = array();
foreach ($row as $col => $value) {
$rowArray[$col] = $value;
}
$results[] = $rowArray;
}
echo json_encode ($results, JSON_PRETTY_PRINT) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment