Get the App
SLTechnology News&Howtos  ›  Development  › 

Codeigniter uses techniques to insert data in bulk

Shulou Source: shulou.com Published: 2022-06-03 07:44:14 10月03日 Update

This article mainly introduces the "codeigniter use skills bulk data insertion method tutorial", in the daily operation, I believe that many people have doubts in the codeigniter use skills bulk data insertion method tutorial, Xiaobian consulted all kinds of materials, sorted out simple and easy-to-use operation methods, hope to answer the "codeigniter use skills bulk data insertion method tutorial" to help! Next, please follow the editor to study!

The copy code is as follows:

$sub_form = array ()

$loop = 0

$ins_loop = 0

$sum = count ($form_datas)

$this- > logger- > info ('insert data total:'.$sum)

/ / using bulk import of things helps to improve insertion efficiency

$callStartTime = microtime (true)

$this- > db- > trans_start ()

Foreach ($form_datas as $item) {

$loop + +

$sub_form [] = $item

If (($loop% 200) = = 0 | | $loop = = $sum) {

$this- > logger- > info ('insert data num:'.$loop)

$res = $this- > kb_object_instance_mdl- > insert_batch ($sub_form,$obj_id)

$ins_loop + +

Unset ($sub_form)

If (($ins_loop% 5) = = 0) {

$this- > logger- > info ('insert data trans_complete ins_loop:'.$ins_loop)

$this- > db- > trans_complete ()

If ($loop! = $sum) {

$this- > db- > trans_start ()

}

}

}

}

/ / $this- > db- > trans_complete ()

$callEndTime = microtime (true)

$callTime = $callEndTime-$callStartTime

$this- > logger- > info ('insert data use time:'.sprintf (' .4f', $callTime))

If ($this- > db- > trans_status () = TRUE) {

$this- > _ show_msg ('1century journal array (' data'= > 'import ok'))

} else {

$this- > _ show_error ('saveOrUpdate error')

}

At this point, the study on the "codeigniter techniques for bulk data insertion method tutorial" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Methods use skills tutorials data learning code more help practical next things efficiency articles theories knowledge articles websites materials follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi Microsoft Huawei Shulou Information