samedi 8 août 2015

sqlite+php - right and fastest way to do transactions with loop

I'm a beginner in php/sql (6 months), and I noticed - transactions are faster than pure "insert into".

When I operate on huge amounts of data (with range: 10-500k inserts), I noticed my script is slow.

The goal: I wanna do the fastest way to save data into sqlite *.db file.

My script looks like that:

$array = array(
    'ronaldo' => 'gay' , 
    'mario basler' => 'cool guy'
);

$db = new Sqlite3('file.db')
$db->query('BEGIN;');

foreach($array as $kee => $val){
    $db->query("insert into table('name' , 'personality') values('$k' , '$v')");
}

$db->query("COMMIT");

Is that way is wrong?

Aucun commentaire:

Enregistrer un commentaire