PHP / SQLite - Copying a table from disk to memory

后端 未结 6 1769
日久生厌
日久生厌 2020-12-30 10:36

I have a sqlite3 database on my harddrive (file.db) with 5 tables. I\'d like to copy 3 of these tables to an in-memory database (:memory:).

Is there a simple way to

6条回答
  •  时光取名叫无心
    2020-12-30 11:12

    If you need a small database for tests, you may export your databse to an SQL file and then execute it as a single query in PHP:

    class EphemeralPDO extends \PDO {
      public function __construct() {
        parent::__construct('sqlite::memory:', null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
        $queries = file_get_contents(__DIR__ . '/database.export.sql');
        $this->exec($queries);
      }
    }
    

提交回复
热议问题