Search code examples
phpsqlitelocal-storagemobile-websiteemplace

Is sqlite database creted on both server and client's device?


i have recently update my website files to my server.but my sqlite database have been createad on the server,but i wanted it to be on the visitor's device. I tought that sqlite was used for offline purpose for websites, i'm a little bit confused plz help me


My script:

class MyDB extends SQLite3 { 
    function __construct() {
        $this->open('mysqlitedb.db');
    }
}

$db = new MyDB();

It is created on my server not on the device


Solution

  • You can have your database either on client device or server side or even in both locations. It really depends on your requirement. If each of your devices want hold their own data itself on the device, its enough to have a DB in client device. If you want to have any centralized location to hold all of your data, you can go for a DB located on your server.

    Sq-lite is a lightweight DBMS and mostly used as a client side DBMS and not recommended to use as a server side implementation.


    And also, Firefox doesn't support SQLite database (in web pages). And it's not part of the HTML5 specification anymore. IndexedDB is the standardized database: http://www.w3.org/TR/IndexedDB/ Mozilla,Chrome and others are working on it.


    The codingg you have with you is in PHP, which is a serverside language and it will execute and perform all of its tasks on the server including DB creation.


    I recomend you to use IndexedDB over SQ-Lite and to use javascript to handle it.

    ex

    var todoDB = (function() {
      var tDB = {};
      var datastore = null;
    
      // TODO: Add methods for interacting with the database here.
    
      // Export the tDB object.
      return tDB;
    }());
    
    /**
     * Open a connection to the datastore.
     */
    tDB.open = function(callback) {
      // Database version.
      var version = 1;
    
      // Open a connection to the datastore.
      var request = indexedDB.open('todos', version);
    
      // Handle datastore upgrades.
      request.onupgradeneeded = function(e) {
        var db = e.target.result;
    
        e.target.transaction.onerror = tDB.onerror;
    
        // Delete the old datastore.
        if (db.objectStoreNames.contains('todo')) {
          db.deleteObjectStore('todo');
        }
    
        // Create a new datastore.
        var store = db.createObjectStore('todo', {
          keyPath: 'timestamp'
        });
      };
    
      // Handle successful datastore access.
      request.onsuccess = function(e) {
        // Get a reference to the DB.
        datastore = e.target.result;
    
        // Execute the callback.
        callback();
      };
    
      // Handle errors when opening the datastore.
      request.onerror = tDB.onerror;
    };