这是网上的一段代码,运行正常,也得到了结果,但运行后这个内存数据表就自动释放了,在别的网页再连接这个表就提示出错,而我想让这个表继续存在,在其它网页中可以再查询这个表,另外内存数据表是否可以定义名字,因为我想建几个内存数据表进行操作。求解!!!
<?php
//open the database, note that ':memory:' is used as filename
$db = sqlite_open(":memory:"); //create a table and insert some data
sqlite_exec($db,
"BEGIN;
CREATE TABLE plays (id, author, title);
INSERT INTO plays (id, author, title) VALUES (1, 'Goethe', 'Faust');
INSERT INTO plays (id, author, title) VALUES (2, 'Shakespeare', 'Hamlet');
INSERT INTO plays (id, author, title) VALUES (3, 'Sophocles', 'Oedipus Rex');
COMMIT;"
);
//select all records from our table
$result = sqlite_query($db, "SELECT * FROM plays");
//fetch them into an array of arrays
$data = sqlite_fetch_all($result);
//display the data
echo "<ul>";
foreach($data as $key => $row){
echo "<li>".$row['title']." (by ".$row['author'].")</li>";
}
echo "</ul>";
?>
<?php
//open the database, note that ':memory:' is used as filename
$db = sqlite_open(":memory:"); //create a table and insert some data
sqlite_exec($db,
"BEGIN;
CREATE TABLE plays (id, author, title);
INSERT INTO plays (id, author, title) VALUES (1, 'Goethe', 'Faust');
INSERT INTO plays (id, author, title) VALUES (2, 'Shakespeare', 'Hamlet');
INSERT INTO plays (id, author, title) VALUES (3, 'Sophocles', 'Oedipus Rex');
COMMIT;"
);
//select all records from our table
$result = sqlite_query($db, "SELECT * FROM plays");
//fetch them into an array of arrays
$data = sqlite_fetch_all($result);
//display the data
echo "<ul>";
foreach($data as $key => $row){
echo "<li>".$row['title']." (by ".$row['author'].")</li>";
}
echo "</ul>";
?>
我再去看看SQLITE对于内存表的定义吧,谢谢to:sibang
这几个表是作为临时数据使用,而且很频繁的读写,数据又不需要保存,我觉得这时SQLITE更适合我的要求,哈哈