4

是否可以使用 Doctrine DBAL 对 SQLite DB 进行批量插入?即使以下更有效:

$twitter = new TwitterAPIExchange($twitterAuth);
    $response = json_decode($twitter->setGetfield($getField)
        ->buildOauth($url, $requestMethod)
        ->performRequest());

    foreach($response->statuses as $r) {
        $statement = $app['db']->executeQuery('SELECT * FROM tweets WHERE twitter_id = ?', array($r->id));
        $tweet = $statement->fetch();

        if(empty($tweet)) {
            $app['db']->insert('tweets', array('twitter_id'=>$r->id, 'contents' => $r->text, 'timestamp' => $r->created_at));
        }
    }
4

1 回答 1

-5

使用 Doctrine2,是的! http://doctrine-orm.readthedocs.org/en/latest/reference/batch-processing.html

Doctrine2 使用 UnitOfWork 模式,所以基本上你可以“持久化”多条记录,然后在最后运行flush- 它会找出插入/更新/等所有数据的最有效方法。这很聪明。

于 2015-05-02T09:43:12.683 回答