# Offline ionic app

**URL:** <https://forum.ionicframework.com/t/offline-ionic-app/50925>\
**Category:** ionic-v1\
**Created:** [May 2, 2016, 7:00am UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925 "2016-05-02T07:00:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sujith008](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sujith008](https://forum.ionicframework.com/u/Sujith008)\
**Post date:** [May 2, 2016, 7:00am UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/1 "2016-05-02T07:00:24Z")

</div>

Hi. i am new to [ionic.my](http://ionic.my) 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.

---

<div class="post-metadata">

**Author:** ![ottz0](https://avatars.discourse-cdn.com/v4/letter/o/46a35a/32.png) [@ottz0](https://forum.ionicframework.com/u/ottz0)\
**Post date:** [May 2, 2016, 8:20am UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/2 "2016-05-02T08:20:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sujith008](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sujith008](https://forum.ionicframework.com/u/Sujith008)\
**Post date:** [May 2, 2016, 8:32am UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/3 "2016-05-02T08:32:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ottz0](https://avatars.discourse-cdn.com/v4/letter/o/46a35a/32.png) [@ottz0](https://forum.ionicframework.com/u/ottz0)\
**Post date:** [May 2, 2016, 8:53am UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/4 "2016-05-02T08:53:22Z")

</div>

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.

> <https://stackoverflow.com/questions/14944936/angularjs-global-http-polling-service>

---

<div class="post-metadata">

**Author:** ![Sujith008](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sujith008](https://forum.ionicframework.com/u/Sujith008)\
**Post date:** [May 2, 2016, 8:57am UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/5 "2016-05-02T08:57:01Z")

</div>

thanks 🙂

---

<div class="post-metadata">

**Author:** ![Sujith008](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sujith008](https://forum.ionicframework.com/u/Sujith008)\
**Post date:** [May 2, 2016, 12:27pm UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/6 "2016-05-02T12:27:15Z")

</div>

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) {  
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);  
}  
if (window.StatusBar) {

```
      StatusBar.styleLightContent();
    }
     
    if (window.cordova) {
    	
        db = $cordovaSQLite.openDB("test.db");
     
      }else{
    	  
        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')");
        });
			  
  });
```

---

<div class="post-metadata">

**Author:** ![ottz0](https://avatars.discourse-cdn.com/v4/letter/o/46a35a/32.png) [@ottz0](https://forum.ionicframework.com/u/ottz0)\
**Post date:** [May 2, 2016, 12:45pm UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/7 "2016-05-02T12:45:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sujith008](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sujith008](https://forum.ionicframework.com/u/Sujith008)\
**Post date:** [May 2, 2016, 12:50pm UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/8 "2016-05-02T12:50:52Z")

</div>

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 🙂 Thanks for the quick response.

---

<div class="post-metadata">

**Author:** ![greycampus](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@greycampus](https://forum.ionicframework.com/u/greycampus)\
**Post date:** [January 9, 2017, 10:54am UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/10 "2017-01-09T10:54:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![saniyusuf](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/saniyusuf/32/13572_2.png) [@saniyusuf](https://forum.ionicframework.com/u/saniyusuf)\
**Post date:** [January 9, 2017, 12:47pm UTC](https://forum.ionicframework.com/t/offline-ionic-app/50925/11 "2017-01-09T12:47:29Z")

</div>

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