Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php将大量行插入sqlite数据库_Php_Sqlite - Fatal编程技术网

使用php将大量行插入sqlite数据库

使用php将大量行插入sqlite数据库,php,sqlite,Php,Sqlite,我有下面的php代码,可以处理10000-20000行,但是如果我需要插入300000000(300k)行,php将超时,或者客户端将关闭选项卡。 有没有关于如何改进代码的建议?下面的代码只是脚本的一部分 $db = new SQLite3('my.db'); $db->busyTimeout(5000); $db->exec("PRAGMA journal_mode=WAL;"); if($q == 'obserations' && isset($_POST['ob

我有下面的php代码,可以处理10000-20000行,但是如果我需要插入300000000(300k)行,php将超时,或者客户端将关闭选项卡。 有没有关于如何改进代码的建议?下面的代码只是脚本的一部分

$db = new SQLite3('my.db');
$db->busyTimeout(5000);
$db->exec("PRAGMA journal_mode=WAL;");
if($q == 'obserations' && isset($_POST['obserations'])){
$van = $db->query("SELECT name FROM sqlite_master;");
    while($array = $van->fetchArray(SQLITE3_ASSOC)){
        $mytables = trim($array['name']);

        $mylines = trim($_POST['obserations']);
        $mylines = explode("\r\n", $mylines);
        $count = 0;
        while(!empty($mylines[$count])){
            $new_obs = $mylines[$count];
            $new_obs = SQLite3::escapeString(htmlentities($new_obs, ENT_QUOTES, 'UTF-8'));
            if(!$db->querySingle("SELECT * FROM '$mytables' WHERE obs = '$new_obs';")){
                if(preg_match("~^http://$mytables/.*$~", $new_obs, $matches)){
                    $db->exec("INSERT INTO '$mytables' (obs, col1, col2, col3, col4, col5) VALUES ('$new_obs', '', '', '', '', '');");
                }
            }
            $count++;
        }
    }
}

你到底想干什么?请添加示例输入数据(
$\u POST['obserations']
?)和表格规格。@timclutton输入数据示例:
http://sometablename/observation-nr1
@timclutton因此,对于sqlite db中的每个表,我们插入一些新行。上面的代码首先匹配每行中的表名,如果行与任何表名匹配,它将转到相应的表并插入新行显示表定义!你有索引吗?@CL.我不知道你想从哪里得到。以上代码就是全部代码