1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| //connection a la bdd
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DB','androiddb');
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');
///// requête sql
$sql = "SELECT * FROM commune";
//getting result
$r = mysqli_query($con,$sql);
//creating a blank array
$result = array();
//looping through all the records fetched
while($row = mysqli_fetch_array($r)){
//Pushing name and id in the blank array created
array_push($result,array(
"id_com"=>$row['id_com'],
"libelle_com"=>$row['libele_com']
));
}
//Displaying the array in json format
echo json_encode (array('result'=>$result));
mysqli_close($con); |