0

我最近将我的网站文件更新到我的服务器。但是我的 sqlite 数据库已经在服务器上创建,但我希望它在访问者的设备上。我认为sqlite被用于网站的离线目的,我有点困惑请帮助我


我的脚本:

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

$db = new MyDB();

它是在我的服务器上而不是在设备上创建的

4

2 回答 2

0

您可以将数据库放在客户端设备或服务器端,甚至在这两个位置。这真的取决于你的要求。如果您的每个设备都想在设备上保存自己的数据,那么在客户端设备中拥有一个数据库就足够了。如果你想有一个集中的位置来保存你的所有数据,你可以在你的服务器上找一个数据库。

Sql-lite 是一个轻量级的 DBMS,主要用作客户端 DBMS,不建议用作服务器端实现。


而且,Firefox 不支持 SQLite 数据库(在网页中)。它不再是 HTML5 规范的一部分。IndexedDB 是标准化数据库:http ://www.w3.org/TR/IndexedDB/ Mozilla、Chrome 和其他人正在研究它。


您随身携带的编码是 PHP,这是一种服务器端语言,它将在服务器上执行并执行其所有任务,包括创建数据库。


我建议您在 SQ-Lite 上使用 IndexedDB 并使用 javascript 来处理它。

前任

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;
};
于 2015-12-13T16:48:42.883 回答
0

SQlite 不是真正的 RDBMS,而是单个文件。因此,您不能像使用 MySQL 和 PostgreSQL 数据库那样进行远程连接。此外,从某种意义上说,SQlite 不是支持事务和数据类型的数据库。如果您需要数据库服务器连接并将数据保存在一个地方,那么您应该更换 SQlite。

于 2015-12-13T17:41:04.383 回答