Bagaimana Cara Melakukan Batch Update dan Batch Insert di Doctrine 1.2 ?

Kita dapat menggunakan Doctrine_Collection [1], untuk proses batch insert kita menggunakan method save() sedangkan untuk update, kita menggunakan methode replace()

Contoh Batch Update

$collection = new Doctrine_Collection('Jawaban');

foreach($kode_soals as $key=>$kode_soal) {

....more code here ...

foreach($prows as $prow) {

..more code here ...

$j = new Jawaban();

$j->id = $prow->id ;

$j->nomor = $prow->nomor ;

$j->kode = $prow->kode ;

$j->nama = $prow->nama ;

$j->tgl = $prow->tgl ;

$j->bln = $prow->bln ;

$j->thn = $prow->thn ;

$j->jawaban = $prow->jawaban ;

$j->pil1 = $prow->pil1 ;

$j->pil2 = $prow->pil2 ;

$j->sek = $prow->sek ;

$j->salah = $prow->salah ;

$j->benar = $prow->benar ;


$j->nilai1 = $nilai_total ;

$j->nilai2 = $nilai_structure ;

$j->nilai3 = $nilai_reading ;


$j->nilai4 = $prow->nilai4 ;

$j->nilai5 = $prow->nilai5 ;

$j->nilai6 = $prow->nilai6 ;

$j->nilai7 = $prow->nilai7 ;

$j->nilai8 = $prow->nilai8 ;

$j->nilai9 = $prow->nilai9 ;

$j->nilai10 = $prow->nilai10 ;

$j->nilai11 = $prow->nilai11 ;

$j->nilai12 = $prow->nilai12 ;

$j->nilai13 = $prow->nilai13 ;

$j->nilai14 = $prow->nilai14 ;

$j->nilai15 = $prow->nilai15 ;

$j->lp = $prow->lp ;

$j->filename = $prow->filename ;

$collection->add($j);

} //end foreach row

} //end foreach kode

$collection->replace();

$collection->free() ;

Contoh Batch Insert

$collection = new Doctrine_Collection('Jawaban');

foreach($kode_soals as $key=>$kode_soal) {

....more code here ...

foreach($prows as $prow) {

..more code here ...

$j = new Jawaban();

$j->id = $prow->id ;

$j->nomor = $prow->nomor ;

$j->kode = $prow->kode ;

$j->nama = $prow->nama ;

$j->tgl = $prow->tgl ;

$j->bln = $prow->bln ;

$j->thn = $prow->thn ;

$j->jawaban = $prow->jawaban ;

$j->pil1 = $prow->pil1 ;

$j->pil2 = $prow->pil2 ;

$j->sek = $prow->sek ;

$j->salah = $prow->salah ;

$j->benar = $prow->benar ;


$j->nilai1 = $nilai_total ;

$j->nilai2 = $nilai_structure ;

$j->nilai3 = $nilai_reading ;


$j->nilai4 = $prow->nilai4 ;

$j->nilai5 = $prow->nilai5 ;

$j->nilai6 = $prow->nilai6 ;

$j->nilai7 = $prow->nilai7 ;

$j->nilai8 = $prow->nilai8 ;

$j->nilai9 = $prow->nilai9 ;

$j->nilai10 = $prow->nilai10 ;

$j->nilai11 = $prow->nilai11 ;

$j->nilai12 = $prow->nilai12 ;

$j->nilai13 = $prow->nilai13 ;

$j->nilai14 = $prow->nilai14 ;

$j->nilai15 = $prow->nilai15 ;

$j->lp = $prow->lp ;

$j->filename = $prow->filename ;

$collection->add($j);

} //end foreach row

} //end foreach kode

$collection->save();

$collection->free() ;

Referensi