Created
January 26, 2019 22:10
-
-
Save eliagbenu/746897d45a5d3065577489510908a1c1 to your computer and use it in GitHub Desktop.
Pull all records
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 | |
$conn = mysqli_connect("localhost", "xxxx", "xxxx", "test"); | |
Header("Content-Tye: application/json; charset=UTF-8"); | |
if (mysqli_connect_errno()) { | |
echo json_encode(array("data"=>"Connection failed")); | |
exit(); | |
} | |
if ($result = mysqli_query($conn, "select * from people")) | |
{ | |
$row_cnt = mysqli_num_rows($result); | |
If($row_cnt>0){ | |
$json_array = array(); | |
while( $assoc = mysqli_fetch_array($result) ) | |
{ | |
array_push($json_array, | |
array( | |
"id"=>$assoc['id'], | |
"gender"=>$assoc['gender'], | |
"dob"=>$assoc['dob'], | |
"first_name"=>$assoc['first_name'], | |
"last_name"=>$assoc['last_name'] | |
) | |
); | |
} | |
echo json_encode($json_array); | |
}else{ | |
echo json_encode(array("data"=>"Nothing found")); | |
} | |
mysqli_free_result($result); | |
} | |
mysqli_close($conn); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment