php生成sqlite db3文件遇到的问题

        $db = new SQLite3('test.db3');
        $db->exec("CREATE TABLE table_1 (
  id int(11) NOT NULL ,
  lessons_id int(11) NOT NULL,
  name varchar(100) NOT NULL,
  url varchar(200) NOT NULL,
  time int(11) NOT NULL ,
  PRIMARY KEY (id)
) ;
INSERT INTO table_1 VALUES ('161', '3583', '背影', 'http://www.test.com/upload/table_1/1369122019-1720.png', '1362988823');INSERT INTO table_1 VALUES ('162', '3583', '从百草园到三味书屋', 'http://www.test.com/upload/table_1/1369122067-9894.png', '1363939234');

INSERT INTO table_1 VALUES ('163', '3583', '繁星', 'http://www.test.com/upload/table_1/1369122095-8678.png', '1364457656');

INSERT INTO table_1 VALUES ('164', '3583', '沁园春', 'http://www.test.com/upload/table_1/1369122117-4050.png', '1365753667');

INSERT INTO table_1 VALUES ('165', '3583', '桃花园记', 'http://www.test.com/upload/table_1/1369122178-5256.png', '1366963200');

INSERT INTO table_1 VALUES ('166', '3583', '晏子使楚', 'http://www.test.com/upload/table_1/1369122201-5046.png', '1368604800');

INSERT INTO table_1 VALUES ('167', '3583', '卜算子咏梅', 'http://www.test.com/upload/table_1/1369122242-8847.png', '1369123200');INSERT INTO table_1 VALUES ('176', '3583', '1-3583', 'http://www.test.com/upload/table_1/20130522143123rop.png', '1369204283');

INSERT INTO table_1 VALUES ('175', '3583', '1-3583', 'http://www.test.com/upload/table_1/201305221431188h6.png', '1369204278');

INSERT INTO table_1 VALUES ('174', '3583', '1-3583', 'http://www.test.com/upload/table_1/20130522142126dkj.png', '1369203686');

INSERT INTO table_1 VALUES ('177', '3583', '1-3583', 'http://www.test.com/upload/table_1/20130522143552zuy.png', '1369204552');

INSERT INTO table_1 VALUES ('178', '3583', '1-3583', 'http://www.test.com/upload/table_1/20130522143555ln8.png', '1369204555');

INSERT INTO table_1 VALUES ('179', '3583', '1-3583', 'http://www.test.com/upload/table_1/20130522152943st3.png', '1369207783');");


功能可以实现,但是效率太慢,平均每10条数据一秒,如果上万条数据,非常慢,求解!



作者: vinson_han   发布时间: 2013-05-24

使用事务啊。如果在没有使用事务的情况下每次执行都会自动代表一次事务进行数据库读写,而不是在内存中操作,效率自然很低。

作者: iminto   发布时间: 2013-05-24

事务不仅仅是可以保证数据一致性,还能提高数据插入效率,达到批量插入的效果

作者: iminto   发布时间: 2013-05-24