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. Thank you so much for providing individuals with a very superb opportunity to read articles and blog posts from this website. It’s usually so terrific and as well , packed with a good time for me personally and my office mates to visit your blog at least 3 times in a week to learn the newest stuff you have. And of course, I’m just at all times pleased with your stunning inspiring ideas you serve. Selected 3 ideas in this article are honestly the most impressive I have ever had.

  2. Thanks for your whole efforts on this site. My mom loves getting into research and it is easy to understand why. We know all of the compelling way you produce functional guides by means of your blog and strongly encourage contribution from other ones on the subject matter so our girl is without a doubt understanding a lot of things. Enjoy the rest of the new year. You are doing a good job.

  3. I wish to convey my gratitude for your generosity giving support to men and women who really need assistance with this important field. Your real commitment to getting the message up and down appeared to be definitely useful and has continuously enabled guys much like me to reach their aims. Your personal warm and helpful guide entails a lot a person like me and a whole lot more to my colleagues. With thanks; from everyone of us.

  4. I would like to show some thanks to the writer for rescuing me from such a instance. Right after surfing throughout the world wide web and meeting solutions which were not pleasant, I assumed my entire life was over. Existing without the presence of strategies to the issues you’ve resolved all through the article content is a critical case, and ones that might have in a wrong way affected my entire career if I had not encountered your site. The capability and kindness in controlling the whole thing was very helpful. I am not sure what I would’ve done if I hadn’t come across such a subject like this. It’s possible to at this point look ahead to my future. Thank you so much for the high quality and effective guide. I won’t be reluctant to suggest the blog to anybody who desires assistance about this subject.

  5. My spouse and i have been so contented when Raymond could deal with his analysis through your precious recommendations he grabbed through your web site. It’s not at all simplistic to just possibly be releasing tips which usually others may have been making money from. We really realize we need the blog owner to give thanks to for that. All the illustrations you’ve made, the simple web site navigation, the relationships you give support to engender – it’s got mostly astonishing, and it is making our son and the family believe that that matter is interesting, which is seriously pressing. Many thanks for all the pieces!

  6. My wife and i were quite joyful that Raymond managed to finish up his investigations by way of the ideas he obtained while using the web page. It is now and again perplexing just to continually be giving for free facts which often the rest may have been selling. So we grasp we need you to thank for this. The specific explanations you made, the easy blog menu, the friendships you make it possible to foster – it’s got all awesome, and it’s making our son and the family reckon that the issue is interesting, and that’s truly serious. Thank you for all!

  7. I have to express my admiration for your kind-heartedness for those people that really need help with that situation. Your special dedication to getting the solution all over came to be rather good and has really empowered many people like me to reach their dreams. Your new interesting guideline implies a whole lot a person like me and further more to my mates. With thanks; from each one of us.

  8. I and also my guys were following the good techniques located on your web blog and before long got a horrible feeling I had not thanked the web blog owner for those strategies. Most of the young men became as a result excited to read all of them and have now simply been taking pleasure in these things. Appreciation for turning out to be really accommodating and also for making a choice on these kinds of wonderful tips millions of individuals are really wanting to know about. My sincere regret for not expressing appreciation to you sooner.

  9. Thank you so much for providing individuals with such a terrific possiblity to read from this site. It is usually so sweet and packed with a good time for me and my office mates to search your web site minimum thrice in 7 days to read the new tips you will have. And lastly, I’m just actually astounded considering the impressive ideas you serve. Selected two tips in this posting are certainly the most efficient I’ve had.

  10. I and also my pals came digesting the nice helpful tips located on your website and then then got a terrible feeling I had not thanked the site owner for those strategies. These guys are already happy to study all of them and already have clearly been having fun with these things. Many thanks for actually being simply considerate and then for obtaining such ideal subject areas most people are really wanting to discover. Our own honest regret for not saying thanks to sooner.

  11. My husband and i ended up being absolutely cheerful that Peter could complete his inquiry by way of the precious recommendations he obtained from your very own site. It is now and again perplexing just to find yourself offering key points which often people have been trying to sell. We really grasp we’ve got the website owner to appreciate for this. The illustrations you made, the straightforward website navigation, the relationships your site make it easier to instill – it’s got most fabulous, and it’s aiding our son and us reason why that topic is brilliant, which is really essential. Thank you for the whole lot!

  12. I actually wanted to type a simple comment to be able to thank you for all of the wonderful tricks you are showing at this website. My time consuming internet look up has finally been rewarded with good quality information to talk about with my great friends. I would mention that most of us site visitors are rather endowed to live in a superb site with so many lovely individuals with beneficial basics. I feel somewhat happy to have come across your web pages and look forward to plenty of more pleasurable minutes reading here. Thank you once again for a lot of things.

  13. My husband and i felt quite lucky that Albert could conclude his preliminary research through the entire precious recommendations he made through the weblog. It’s not at all simplistic to simply find yourself giving for free instructions which people today might have been making money from. Therefore we figure out we now have the writer to thank for that. The most important explanations you’ve made, the easy blog menu, the friendships your site give support to instill – it is mostly unbelievable, and it’s letting our son in addition to us reason why the theme is exciting, which is exceedingly indispensable. Thanks for everything!

  14. I definitely wanted to develop a small message to be able to express gratitude to you for all of the splendid facts you are showing at this site. My time consuming internet lookup has at the end of the day been paid with extremely good ideas to share with my company. I would suppose that many of us website visitors actually are extremely blessed to exist in a very good place with so many awesome people with good pointers. I feel very much lucky to have come across your entire web site and look forward to so many more entertaining minutes reading here. Thanks a lot once again for all the details.

  15. I would like to show my passion for your generosity giving support to men and women that actually need assistance with this study. Your real commitment to getting the message throughout had been remarkably practical and has regularly encouraged regular people like me to reach their endeavors. Your amazing invaluable help indicates a great deal a person like me and substantially more to my office colleagues. Warm regards; from each one of us.

  16. I happen to be commenting to make you be aware of what a beneficial experience my girl undergone using your site. She discovered so many issues, which include what it’s like to have an incredible giving character to get other people smoothly comprehend some impossible matters. You truly did more than our own expectations. I appreciate you for imparting those great, trustworthy, edifying as well as fun tips about that topic to Ethel.

  17. I’m just commenting to make you know what a really good experience my daughter had viewing your site. She noticed many things, which included what it is like to have an incredible coaching style to let other people with ease completely grasp some problematic things. You really did more than her desires. Thanks for imparting these interesting, trustworthy, edifying and as well as cool guidance on your topic to Ethel.

  18. I intended to compose you one little bit of word to thank you yet again with your wonderful solutions you’ve featured on this site. It was certainly pretty generous with you to grant extensively exactly what a number of us would have offered for sale for an ebook to earn some cash for themselves, most importantly seeing that you could possibly have tried it if you wanted. These thoughts also acted like a good way to fully grasp many people have a similar passion really like mine to realize a good deal more when it comes to this issue. I know there are several more pleasurable instances up front for many who look over your site.

  19. Thank you so much for providing individuals with an extraordinarily special possiblity to read articles and blog posts from this blog. It is often very brilliant and as well , jam-packed with fun for me and my office friends to search the blog the equivalent of three times weekly to read through the fresh items you have. And of course, I’m so certainly impressed with all the great principles you give. Certain two facts in this article are easily the finest we’ve had.

Leave a Reply