I am writing code to get data from MySQL database and using Vuejs,
this.$http.get("api.php?action=read")
.then(response => {
console.log(response);
}, error => {
console.log(error);
});
this request returns all api.php content and doesn't return the data.
here is the api.php file
<?php
require_once('include/config.php');
$res = (['error' => false]);
$action = 'read';
if (isset($_GET['action'])) {
$action = $_GET['action'];
}
if($action == 'read') {
$images = array();
$query = 'SELECT * FROM images ORDER BY id DESC';
$select_images = mysqli_query($connection, $query);
while($image = mysqli_fetch_assoc($select_images)) {
array_push($images, $image);
}
echo json_encode($images);
}
mysqli_close($connection);
header("Content-type: application/json");
echo json_encode($images);
die();
?>
Can anyone help me, Please?