Offline ionic app


Hi. i am new to requirement is to create a mobile application for an existing website which is created using codeigniter and mysql db.Now my client wants the app to work in offline mode.How to achieve that??.Does it requires firebase / other db for app ??.if so how it syncs with the mysql db of my website ??Thanks in advance… && Sorry for my bad english.


I think you have to use sql lite or local storage. Offline is offline and CI is php so you need a web server to serve it and an internet connection to access the database.

If you need it offline you need to make the database in sqllite or local storage. 2 separate things. If you need it to sync then it needs to be online in order for it to sync. If that is the case, you need the database to output json and your Ionic to make Ajax requests to access the data needed as Ionic is not a serverside technology


By offline i mean that the app has to work well in case there is no network connection not completely offline without server .Consider if offline and user completes a form and submits it has to be saved locally.When connected to network i have to update that to server.How can i achieve that


Look at Angular polling where Angular constantly checks for a connection and if it is $timeout caches the request and sends it when the connection is established.


thanks :slight_smile:


I have tried sqlite.I want the save some common fields from my web db to my mobile db.I got this piece of code from a source…Is it a correct method??.Each time i reload the web the values are inserting into websql db .how can i avoid inserting repeated value??Any other method to sync my live db to device db??

$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
if (window.StatusBar) {

    if (window.cordova) {
        db =  $cordovaSQLite.openDB("test.db");
        db = window.openDatabase("test.db", '1', 'ecohub', 1024 * 1024 * 100); // browser
    	$rootScope.db = db;
	    db.transaction(function (tx) {
	    	  		tx.executeSql("CREATE TABLE IF NOT EXISTS gender (gender_id int NOT NULL PRIMARY KEY , gender_name varchar )");
	    		tx.executeSql("INSERT INTO gender (gender_id,gender_name) VALUES"
	        			+ "(1, 'Male'),(2, 'Female'),(3, 'Others')");
        	tx.executeSql("CREATE TABLE IF NOT EXISTS expense_category (exp_cat_id int ,exp_cat_name varchar)");
        	tx.executeSql("INSERT INTO expense_category (exp_cat_id,exp_cat_name) VALUES"
        			+ "(1, 'Mileage'),(2, 'Travel'),(3, 'Accomodation'),(4, 'Subsistence'),(5, 'Consumables'),(6, 'Others')");


Not too sure on this one…Have you assigned values in the form fields or somethnig? Can’t you make a RESTFUL post request from your form app to your external DB on your server using the $http? If the request is not sent or there is no connection save it as local storage as an object. Use polling to check for a connection, then send it again.

I’m learning Ionic also so you may need to use the post request it to a php CURL script that then connects to your MYSQL, Not too sure on Cross domain either using Ionic


I am making RESTFUL post request from my app to my external DB.i just want to show how i save data using web sql and make sure that i am going in right track :slight_smile: Thanks for the quick response.


@Sujith008 have you found any solution? am also looking for the same.


We use PouchDB to achieve a very simple offline first experience and have a Cloudent back end which syncs automagically since its CouchDB based.