我有一个SQLite3文件,该文件已从网络读入内存(作为字符串)。我想打开它并查询它。我知道SQLite3可以使用:memory:
描述符创建空的内存数据库。但是我想知道如何在不接触磁盘的情况下加载现有的数据库。
目前,我正在这样做:
$tempName = tempnam(sys_get_temp_dir(), 'sqlite3-');
$temp = fopen($tempName, 'w');
fwrite($temp, $cache->getDB($cacheKey));
fclose($temp);
// Delete the temp file when we're done.
register_shutdown_function('unlink', $tempName);
// ...
$db = new SQLite3($tempName, SQLITE3_OPEN_READONLY);
// Query the DB
$db->close();
这可以正常工作,但是它不必要地接触磁盘。
我已经见过this answer,但这只涉及C,不涉及PHP。
我也尝试将文件保存到php://memory
,但是SQLite3无法打开它。