简体   繁体   English

从多个数据库文件中选择所有行-PHP sqlite3

[英]select all rows from multiple db files - php sqlite3

I have multiple db files which contains the same table with different values. 我有多个数据库文件,其中包含具有不同值的同一表。

example files: 示例文件:

wifi_16-09-02_09_34_03.db wifi_16-09-02_09_34_03.db

wifi_16-09-02_09_44_06.db wifi_16-09-02_09_44_06.db

wifi_16-09-02_09_60_02.db wifi_16-09-02_09_60_02.db

How can I select all the rows from multiple files? 如何从多个文件中选择所有行?

I only know to do this with one file. 我只知道用一个文件来做。

Here is my code: 这是我的代码:

  $dbfile = 'wifi_16-09-02_09_34_03.db';
  $db = new SQLite3('dbs/'.$dbfile);
  $sql = 'SELECT * FROM wifi';
  $results = $db->query($sql);

I am new on SQLite3 , any help would be appreciated. 我是SQLite3新手,将不胜感激。

You can simply open the other databases in the same way. 您可以简单地以相同方式打开其他数据库。

If you want to have all rows in a single query, you need to attach all the other databases to some main database, and use a compound query : 如果要在单个查询中包含所有行,则需要所有其他数据库附加到某个主数据库,并使用复合查询

$db->exec("ATTACH 'dbs/wifi_16-09-02_09_44_06.db' AS db2");
$db->exec("ATTACH 'dbs/wifi_16-09-02_09_60_02.db' AS db3");
...
$sql = <<<'SQL'
    SELECT * FROM main.wifi
    UNION ALL
    SELECT * FROM db2.wifi
    UNION ALL
    SELECT * FROM db3.wifi
SQL;
$results = $db->query($sql);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM