Home > Tutorial > Drupal: Bulk Insert

Seringkali ketika melakukan coding kita memerlukan proses insert ke database dengan data lebih dari satu. Misalnya akan menambahkan data student sebanyak 10 orang dalam satu waktu.

Cara paling simple adalah looping dari array student tersebut, dan insert satu persatu datanya ke database. Cara ini sah-sah saja, tetapi membutuhkan 10 kali proses insert data. Artinya aplikasi melakukan komunikasi ke server database sebanyak 10 kali. Apabila salah satu gagal, maka hanya record tersebut yg gagal. Contoh kodenya sebagai berikut:

Ada cara yang lebih bagus/optimize untuk melakukan hal tersebut adalah bulk insert. Pada prinsipnya cara ini adalah melakukan proses insert 10 data dalam 1 kali eksekusi saja. Apabila salah satu gagal, maka seluruh proses dibatalkan. Contoh kodenya adalah sebagai berikut:

Itu saja tentang bulk insert.

Happy coding!

You may also like
Ciyeee, Drupal dan WordPress minta update barengan.
Membuat Chart di Excel menggunakan Drupal
[Drupal] Mengubah tampilan menu local task dari tabs menjadi dropdown
Tabulasi data menggunakan views pada Drupal 7

58 Responses

  1. I am just writing to let you be aware of what a perfect encounter my child went through checking your web site. She even learned so many things, not to mention how it is like to have an incredible helping heart to have the mediocre ones without difficulty understand a number of complicated subject areas. You truly surpassed our own expected results. I appreciate you for presenting these valuable, trusted, revealing as well as cool guidance on your topic to Kate.

  2. A formidable share, I just given this onto a colleague who was doing a bit of analysis on this. And he in reality bought me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for spending the time to debate this, I feel strongly about it and love studying more on this topic. If attainable, as you become expertise, would you mind updating your weblog with more details? It’s extremely useful for me. Big thumb up for this blog post!

  3. I am only commenting to make you know of the helpful encounter my child obtained browsing your web page. She came to find a lot of details, with the inclusion of how it is like to have an incredible helping spirit to let certain people very easily learn about certain impossible topics. You undoubtedly surpassed readers’ desires. Thank you for producing the great, trustworthy, revealing and as well as unique tips on this topic to Evelyn.

  4. I and also my buddies appeared to be checking out the excellent solutions on your site then before long developed a terrible feeling I never expressed respect to the blog owner for them. All the women were definitely consequently passionate to learn all of them and now have undoubtedly been using these things. Appreciate your being well considerate and then for selecting this sort of good things most people are really desirous to understand about. My very own honest apologies for not expressing gratitude to earlier.

  5. Youre so cool! I dont suppose Ive read anything like this before. So good to search out somebody with some original thoughts on this subject. realy thanks for beginning this up. this website is one thing that is needed on the net, somebody with somewhat originality. helpful job for bringing something new to the internet!

  6. Oh my goodness! an amazing article dude. Thanks Nevertheless I’m experiencing issue with ur rss . Don? know why Unable to subscribe to it. Is there anybody getting identical rss problem? Anybody who knows kindly respond. Thnkx

  7. I would like to express my love for your kind-heartedness giving support to all those that really want help on this important situation. Your personal dedication to getting the message across appeared to be extremely effective and has really encouraged women much like me to get to their desired goals. Your new informative useful information signifies much to me and even further to my office workers. Thanks a ton; from everyone of us.

  8. I wish to show my admiration for your kind-heartedness in support of men and women who must have guidance on that issue. Your very own dedication to getting the solution across became extremely effective and have continuously allowed those much like me to achieve their desired goals. Your amazing useful guide indicates this much to me and further more to my fellow workers. Thanks a lot; from each one of us.

  9. I? impressed, I need to say. Really hardly ever do I encounter a blog that? both educative and entertaining, and let me inform you, you’ve gotten hit the nail on the head. Your idea is outstanding; the problem is something that not sufficient persons are speaking intelligently about. I am very glad that I stumbled throughout this in my seek for one thing referring to this.

  10. My wife and i were now excited Louis managed to do his researching with the precious recommendations he was given through your weblog. It is now and again perplexing to just always be giving out helpful tips which other folks may have been selling. And we also do know we now have the writer to appreciate for this. All of the explanations you have made, the straightforward site navigation, the relationships you give support to create – it’s got everything incredible, and it’s really leading our son and the family understand this article is brilliant, which is exceptionally indispensable. Thanks for the whole lot!

  11. I’m typically to running a blog and i actually recognize your content. The article has really peaks my interest. I’m going to bookmark your web site and keep checking for brand new information.

  12. Aw, this was a very nice post. In concept I would like to put in writing like this additionally ?taking time and actual effort to make a very good article?however what can I say?I procrastinate alot and certainly not appear to get one thing done.

  13. I precisely wished to appreciate you all over again. I do not know the things I could possibly have implemented in the absence of those solutions contributed by you relating to my situation. It was actually an absolute fearsome setting for me, however , coming across the very professional manner you resolved the issue made me to leap for gladness. Now i am thankful for the service and as well , hope you really know what a powerful job you happen to be doing training others through the use of your blog post. Probably you haven’t met any of us.

  14. After study a couple of of the blog posts in your website now, and I actually like your manner of blogging. I bookmarked it to my bookmark web site listing and shall be checking back soon. Pls check out my web site as effectively and let me know what you think.

  15. I precisely needed to thank you very much all over again. I do not know the things that I might have taken care of without these information documented by you about this subject matter. This has been a very intimidating case for me, nevertheless taking a look at this specialized avenue you solved it took me to cry over fulfillment. Now i’m grateful for this advice and thus hope that you really know what an amazing job you are always providing training most people through the use of your web page. I’m certain you have never come across any of us.

Leave a Reply