Connect to remote database

Hello,
I started last week to create some new apps with Ionic.
Right now, I need to create an application that connect to remote database, I send a request (query) and i receive the answer from the mysql database.
Please, can you help me?

1 Like

https://docs.angularjs.org/api/ng/service/$http

then you need an api and an endpoint to get the data you want from your backend.

Hello @bengtler,
but where I set the connection with the database?
I mean: db_name, login_sa, password_sa

thats done in your backend --> simple example:

you have a php file on a webspace or server -> http://example.com/api/myPHPAPI.php?action=getData

in the php file you get the parameter action --> and that calls a function to get data of your database --> so you php scipt connects to your db and loads the data and sends them back to your frontend.

All what you need to do in your app ist sending a http-request to that address and waiting for the answer :wink:

So, how to read this php file?

ehhhm maybe you should read something about writing backends… creating apis and so on…

it is the easiest step to connect a dbs with a script language.
and it would be not that good if you read out your backend files :slight_smile: .

the php-file contains your backend logic (reading and setting data, processing data).

easiest way to send response is to use the “echo” command in php --> keep in mind that you need to convert your response content to json ;),

If this all is unclear… please read tutorials about backend-programming-technologies and so on.