douzao5487 2015-12-13 16:39
浏览 105
已采纳

是否在服务器和客户端设备上创建了sqlite数据库?

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

  • 写回答

2条回答 默认 最新

  • donglun4521 2015-12-13 16:48
    关注

    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;
    };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?