Skip to content

Instantly share code, notes, and snippets.

@AladinDridi
Created December 19, 2017 10:19
Show Gist options
  • Save AladinDridi/655f2483a24dc4887bfefba70839368c to your computer and use it in GitHub Desktop.
Save AladinDridi/655f2483a24dc4887bfefba70839368c to your computer and use it in GitHub Desktop.
json php gist-working code
<?php
$mysql_db_hostname = "localhost";
$mysql_db_user = "root";
$mysql_db_password = "";
$mysql_db_database = "calendar";
$con = @mysqli_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password,
$mysql_db_database);
if (!$con) {
trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}
$var = array();
$sql = "SELECT * FROM users";
$result = mysqli_query($con, $sql);
while($obj = mysqli_fetch_object($result)) {
$var[] = $obj;
}
echo '{"users":'.json_encode($var).'}';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment