What is the best way to get data out of your database with ionic


#1

I have a mysql DB and was wondering what the best way is to retrieve this data using Ionic.
I have tried it with Sequelize but can’t seem to make it work.

Does anybody have a suggestion or can point me in the right direction? Thank you


#2

I’m using $http in my controller to receive data from a php file on the server.

  $http.get('{path_to_php_file_on_the_server}')
    .then(function(response) {
    $scope.dataForTheView = response.data;
  })

The php file gets the data from the db and encodes it to JSON.

$utfQuery = "SET NAMES 'utf8'";
mysqli_query($db_connection, $utfQuery);

$query = "SELECT * FROM table";

$result = mysqli_query($db_connection, $query);
$data = array();
while($row = $result->fetch_assoc()) {
  $data[] = $row;
}
echo json_encode($data); // Important

I’m thinking to create a REST server with Laravel (php framework) to send some REST commands with Ionic and receive the data.