Created
December 19, 2017 10:19
-
-
Save AladinDridi/655f2483a24dc4887bfefba70839368c to your computer and use it in GitHub Desktop.
json php gist-working code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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