Ionic Framework and PHP

Hi Im new the Ionic and the Mobile App building scene, I have a question though about how apps can interact with a Database, I tend to use PHP alot and I was wondering if the Mobile App can actually use them?

Does PHP files have to be hosted on a website/server and the Ionic App has to query it? Or is it possible to have the PHP files hosted inside the app?

Regularly I use jQuery and the below would be an example of an ajax query.

$.ajax({ url: 'http://domain.com/my/userUpdate.php',
         data: {action: 'test'},
         type: 'post',
         success: function(output) {
                      alert(output);
                  }
});

http://domain.com/my/userUpdate.php where would this file need to be hosted?

I’ve heard of embedded applications with php, I do not think it’s right.

If you want to store data locally on your application use localStorage or WebSql from HTML5.

If you want remote store can use php and create an api for communicating with the application. (Eg JSON)

Running php on the mobile? That would be nuts lol. It’s totally fine if you want to build a webservice using php to be able to store data remotely and use it via jQuery ajax, but honestly, look at Angular $http service, it can fully replace $.ajax and it’s already built in.

So the PHP files have to be stored elsewhere and queried either via ajax or $http

You do seem to have cross purposes here, I’d say there are several things at play and it all “kinda depends”

Why do you want to use a database?

The thing to understand about ionic is it is intended as hybrid framework, ie. you use something akin to cordova to give you a webview on the phone that then executes local javascript, the local javascript is your way to create the interface, talk to the internet and talk to the phones hardware to do things like local storage.

Now I could be wrong here, but it “sounds” like what you want is to call information from a remote data source and you are trying to use ionic like a client-side framework served from the web server, akin to say jquery mobile or bootstrap on a standard web page. This is not what ionic is about.

You need to either:

  1. create a php web service linked to your database that allows the client side (on the device) to ajax call your webservice
  2. use local storage via javascript and not a remote database, but then it depends why you think you need a database

All in all, I think you may have the wrong end of the stick somewhere here :slight_smile: