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条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装