Featured image of post Insert Banyak Data Sekaligus ke dalam Database PHP MySQL

Insert Banyak Data Sekaligus ke dalam Database PHP MySQL

Gak kebayang kan kalau datanya ada 1000 tapi kita harus masukin data tersebut satu per satu ke tabel di database. Nah, maka dari itu kita bisa pakai PHP buat masukin data yang ribuan tadi ke dalam database secara bersamaan dan tanpa membuat server database kita overload.

Terkadang saat kita membuat sebuah program ada momen dimana kita harus memasukkan data yang sudah ada ke dalam database. Gak kebayang kan kalau datanya ada 1000 tapi kita harus masukin data tersebut satu per satu ke tabel di database. Nah, maka dari itu kita bisa pakai PHP buat masukin data yang ribuan tadi ke dalam database secara bersamaan dan tanpa membuat server database kita overload. Langsung aja kita cobain ke studi kasus.

Desain Tabel MySQL

sebelum masuk ke datanya, kita bikin dulu sebuah database baru dan buat tabel di dalam database tadi. Untuk membuat database bisa jalankan perintah ini atau buat melalui phpmyadmin.

1
CREATE DATABASE IF NOT EXISTS `belajar_input_banyak_data`

Lalu buat sebuah tabel di dalam database tadi. Struktur dari tabel yang bakal saya buat adalah sebagai berikut:

name type
id int
kode varchar(10)

Kita bisa membuat tabel diatas melalui phpmyadmin atau menggunakan query sql sebagai berikut:

1
CREATE TABLE `data_kode` (`id` INT NOT NULL AUTO_INCREMENT , `kode` VARCHAR(10) NOT NULL , PRIMARY KEY (`id`))

cara membuat tabel lewat phpmyadmin

Setelah membuat database dan tabel, selanjutnya kita bisa langsung membuat kode untuk insert data banyak data sekaligus di php.

Data yang diperlukan

Misalnya saya punya data dalam bentuk array pada PHP seperti berikut:

1
$data = ["3Ym1Kb","4J1cvK","HKKYmb","mHY1YH","x2bc31","c4c43c","xJ2KH1","vHJ2v3","JmYYJb","2v4JKJ","2x1mm2","HKHcK1","cx4JJm","cYYx1x","b4b21m","bvxxm4","2Hm331","bv3YxH","K132HK","4HHKvx","Hv341H","bH1J1H","vvJ1mY","4xH2Hm","cHb33H","vxJ1HY","24H1vH","Hcbvm1","4Hvx31","mKKxmJ","vYKb4H","m3bxx3","H334HJ","1KYKbm","m2v4KY","HmKHJH","Kbvm2m","cH33c4","2YHHYH","xJ34Kc","2YY11K","1cH2bm","b23m3H","2YvHYx","2JKHK4","KvcYcc","HmbHJc","YYJ133","vY1cY2","YvmYYK","K2Y34H","cKHJxH","4mmH4K","cJmJ1m","H2b221","mKc32x","H2v2K1","2H3HKK","c13HHb","JJYxxc","JH11mJ","YbH11K","HYm3HY","HKY1mx","4KY4K1","vm43xc","xv4Kmc","KH242b","3c4cJY","bHJ31c","vHJvKY","b2vJHY","HHHxbY","m3cHcv","Jb2H1m","KYYYYH","Jmmmvx","2b4Hvc","Y43cYH","x221vJ","Yb32Hc","YbYxKm","KHYKK3","YK1bv4","HKK34H","xHY1JY","v3c4vb","K2xmYK","xJvcxm","144cYJ","YHH1mJ","Y2Hb4J","213H1J","bm422K","3bJYmm","H3324c","vJvJ3H","HmJ2J4","4bvv13","KvcYY2","HmJHxK","142122","mYvxx4","1J3433","14KY24","v4c1b4","J1v2mx","b421x2","x3v23K","Jm23m4","HvHJ2H","22333K","4b22cx","KJx14J","HKH322","4cHYx2","3bcYbb","x3x2Hx","HvH2x3","bHc3Jv","bHKKcJ","xHHc3m","4bH4x1","43bbY4","4K1Ym1","bKHH3v","2KHHxb","cHK12H","Yvxvcb","1132vb","cvm4J2","v1xKJH","Hmmx4Y","xmx2Hm","cHYbYc","1cb3Y3","b1c3J4","xv4Hxc","HHJ4Hc","c34mmK","JbxKHK","cxKxv1","1vv4mc","13HKvK","xYYJJ3","bmxmHc","HK2b1H","421ccv","Jv44KY","2vJvY2","bH1vH3","xx43YY","31c13b","JccJ2H","2bKv31","J21bb3","KKv2xY","YJH42v","xmHHbY","31Y2m3","221cc3","ccxbbY","K2c42J","bxmKKb","YvJHK2","vH4Hv2","42KYH3","1ccHcH","H4Yv2m","KvY4cb","131b3J","v43mYH","KHHJvY","HHbKvH","K1Y43c","Y4KKm1","mKmcKH","1cHHYb","J1m13H","3J1J4b","Kx34K4","4HYHbb","2JxJbK","mbbxxx","2mb3K3","c4JYHY","4Y43K2","xmJc3H","bcmmxc","mYvcc2","c4HvHH","Kvm32m","K4mcYJ","442JJ2","Y3vxHH","24KJxH","ccxH2K","Ym1H4K","JH2mHc","2JxKx4","c33Hcx","HKxmmY","JxHH3v","3m14x4","3mH14c","x3KcYY","JY2J3b","cb22JY","m2HHHv","Hb2J2H","1x44bH","cx4xY3","cJ3m23","v1vvvH","YJcbvK","HvvxYm","4v32H3","vcJmK2","YHm31H","bHm4v1","bvH4xv","YKJm33","K3KJcx","b3Y1H1","1b3m3x","KmH122","Jbbm4Y","HHJKv3","Hb4J3m","m2YvK2","bHvYYH","K4J2cY","JY1H4m","xv4xJ3","J2124m","xbHKc4","HHYHx4","YJbx3H","HHbKc2","mxbxxc","cmJbJ1","bJxH44","c3x42K","KvJJHm","31vJ31","4b44Hx","H22mm4","vJ31YH","xbbJH2","1H4cH3","m1KKb3","1K4c4H","41cK4c","JvcKv1","HY11v4","2xv3Yx","YHxm1H","3YbYHJ","4xKJJY","3222Yb","1Kb2Yv","HJ42H1","x31bHm","xvmbb3","K4bvK3","ccxYvm","2xxJ2H","KvxJ2H","3Jx2v1","cbmJ22","xv3c4b","mbHxYc","mH2x3c","Hb1v24","HJxHvK","KKmmY3","HHm3mH","xvcx1v","2xHcvK","YYxHxJ","3x3Ymb","J1ccHH","Ym3cb3","4HHbHv","x4mKv3","13HHYH","xHcJJ4","1HJ4mb","H132c2","xHHYKb","bcHJYY","HHJHHY","m4xvvJ","mb21vc","cm3bJ2","YHH4K4","2bxcKH","bxHv2m","2HYHYm","b4Y4cJ","vHmKxK","HH4Yc2","b1cHKH","HcJmm4","JYm43J","b21x4K","xJ413K","bJxHvb","YmKK13","3m3cH1","1bK24x","HHYJKH","1xxHHm","YKH1bK","HYHHHb","42HH1H","vvYx2c","mb4cHK","4KKx2H","1bm2cm","b1YxKH","vv411H","H3c1b2","bcHJHJ","32H1vc","J2J1HH","Y4bHKx","2cbv44","KcHcKY","bJmJ4m","bx2Jmm","bm4mxb","3mJKb1","v3xbc2","xm4Hm3","1HbHH4","bJbYH4","mmHxxx","Hxv1Hx","Jc34JH","1YcHKH","4Hbv1J","xY3cvY","b2cv4H","vxm4H4","xKcHKY","1mxmK3","YYcH2H","2JmH3H","KHcvmH","cH4mY3","mHHHHH","K2v4HH","Jbm22m","cH122K","Hx4vxH","m4m442","vcY2xv","YxcKmK","4K1cYH","vKK2Hm","3b4mbc","HK2vJK","1m34HH","1mJmHJ","YY1vcx","vbxHJH","H3Y4K1","KJcmYm","3Y444K","YH4mvc","4xxK3v","JH1JKH","v2K323","H2JbvH","1vc31H","b2mvJK","cJ42J2","mHJxH2","Y11mmJ","vmx1bJ","x13JJJ","4KHHHK","x1HH2c","bccxb1","124J3x","JYKHbY","cv4cJv","4c2HH4","3vJ3Hb","4bbmc2","Ym23YJ","Hvvc1H","cH1vY4","vHvK1J","v11m1H","J2mHJJ","3v4Hc1","cvHYHb","x43cxx","YHx1Ym","vxYHmK","v41c32","JJ232J","HKK1Hx","Y322YK","vmKH2x","YcHYHx","4xv1cb","mHmHHv","vJ21c3","Jxm2YH","1JHv4H","bYmvcx","vcHJJm","13vJc1","2KJxY4","3mv4KH","YHxmbm","Y1H23x","vv4v1K","Km3KKm","JJb2Kc","KHxHJH","13vb2x","YK44J1","m3b2HH","vm4H4v","KJxKxJ","2J4HJm","vvJHHK","b3b4HJ","4cbHY3","vH3YvJ","HbH3HK","1c4b2m","mHcmK3","24mH2b","432KmY","HKv2Ym","K1H1xY","bx3vm1","mKY32v","2KKKbH","HYx41x","xcHKH3","31HH2Y","KJbbYb","vHvHvK","H2cYKm","v1xcHm","c424vx","1bKYv1","Y4H33v","Ybmc4Y","K3H3Kb","vv14bK","44vmb1","HK3bHK","JKxc1v","4mHHx2","2cxJY2","2J33Yc","bcbb31","xH1KHx","xKmvc4","44Yvvm","3xmHm1","2xH2c2","m31vxJ","HY4KHK","2b412b","m23c1H","b1mm4Y","HKYvc2","bvbxYH","xJ1Hxb","cxH1KK","HY4vmx","YH2c2H","xH41xJ","41YHHm","HvYY4v","221324","mc2YJJ","vHb131","YYYJ2J","1c1cK2","22cKv3","3JHcmv","Hb1Y33","11HHmK","12Jxxm","42mxH4","KxvH34","1Hc4b1","HH24JH","1cKH43","cvKmbH","2HcmY3","Hxx4m2","3cY1HJ","YxYx14","Kbvbcb","32HxcY","4H43YK","1KJHmK","33vcHx","2cH44c","c23vHm","3Y232H","mJH4mx","KvYKJx","xYcbY3","v1b22b","K21YHb","xKcH13","Hmx44m","JcH1xH","vKbb33","cJx1c2","HcbmY4","H1Y1HJ","KmvKYm","JHbJcm","cbYKY2","KxvK3Y","Kb3cYx","m1J2KJ","cYmm4b","mKJcvc","cJJHb1","KYKcHJ","2H3vJ1","22b1Y4","YxJH41","JxYc33","cJvmH4","2HbK32","xccHKH","m2cm3c","KHb4c2","ccJxb3","mmx2bY","Y2HbHb","v3KJJH","K1J4Kb","xYv3HH","31H1J3","x3b1xH","2K4m42","bHcm24","213Kcb","JJ1x44","12vcK3","31cJK2","x2mKx1","H3H1Jv","KxHJHH","1mY2KK","bHmmbm","m3Hcx4","bbJm1b","cbvmx3","HK4HvK","H1x11K","H2bm2Y","c4mvbc","cxmJYK","JJJK12","Hbm3bJ","x1mHxH","HbK32v","2J2mxv","1c3KJ1","Jv31H4","Kbm4bK","cHvcbx","3bmHmH","4KJYbm","J4HHvH","cx3JxH","KmHx2K","cvcc13","Jx233c","YH1J11","JHHcHb","J2vv3K","xKcHm4","xm4bvm","mK1H1J","mvxKbK","xK3JJH","b4JK4x","H41c43","m21m3H","vx1b1m","2mmmvY","vbvx4H","KH42K4","44mJ4c","3HHvm2","mxK4mb","Y3mK4v","mcJ3Hc","c2bb23","bK2xHY","221HKm","1xvm2m","b3cv3m","4cvH3v","vJKxK2","xbvmx2","Kvv24H","HmvHm2","12Yxbv","1Y1JcH","Y1HKHc","vHKKJ3","2m1H1x","bx44J3","4b24Hv","Y2K1K3","J2HYHH","3cxvmx","2KK2vK","xb133v","bbmm2v","1v33Jv","22vvY3","1Kv4vv","bb2vm2","b4mHY1","cbxmH1","HJ4313","vcYYKb","JHHmmH","mcJHbH","YH2mcJ","3x1xYx","Hb41cK","4HH1K2","b2YK2H","41bbJH","JHH2Hm","HK4144","H2Jmbb","bKcc12","2mvYmH","vxbv24","1c2vmx","JYvxcm","bb1cHH","HJbH4Y","JHKbxJ","HJvbx3","1vm3K3","3442bc","4YcHm2","4JJ2Hm","v4K3m4","2JxHcY","KJ3bKY","2YY3mH","4Ycc2x","KHJ1HH","Kx2242","YmvJ2c","b122cJ","H214Hm","Y4HxbY","1K4xKH","HmvHH3","4mbmHJ","H31HcK","HcJ1Yc","42mmHc","J42mJ4","v1Y4c3","4H1mvx","KKx1vm","xJH24m","mbKvKv","xY1vJv","Yb2YmH","c2mJc3","Kmc14c","3c41YY","cJKbHc","42m4m4","2c2KJb","3HmvHK","Y2m1bH","HH1x2m","bvHmK3","cYxJJ3","Y1cYKx","mv2cJc","mcxHmc","b4cc4x","1b132H","K2bYHK","3Y2xbK","bHJJvJ","Hx34H4","cYm4v2","2J3HHK","mv1YbY","Jm2m2H","c23cmY","mHbmKm","K1vJ3x","2m3H34","1HY42H","KbYH2Y","J4xKHx","x4HJ2c","xKJY43","Y2c31m","KH222H","JKKKbH","YJc2c4","mv3H1J","v43xKH","vYJ4bm","Hb4mvc","KvmKbm","YvJ134","cYv3bb","Y3144Y","3YYKbY","HY3bvH","bbv1b2","YY13KH","cH3YYb","HHxK34","HYxm1v","c2xmmc","2YY3Hm","J4YYx3","3xmmHY","mmxb33","mJxvKb","H1JmKm","HvJbbc","YJc1mb","cHKKcH","33H12J","HY2YxY","HmHJHb","b32xJ2","4b2H24","HYJHHK","xYcKHc","YKK2cx","214JvJ","YHmm3v","H2mx2H","3vHx4K","HHHx2v","xcHmxb","Jm43cx","JHKcH1","vJ3cvY","K3b11b","4KJxc2","Y4KmK3","HJvmx2","b1mK2b","YHH2Jm","vHmKKv","JJHKbK","c31bc4","JbbKHK","YmHb44","b14H4H","KbHHmv","bH1bb3","vHm3xx","mH1bmc","41H3v4","3vHYcb","HxHK3J","KYHHm2","b1YKKY","KvHKvJ","xbv23x","HKKJJ3","bK243x","KHHJJb","mKc321","xKHH33","3mbHbx","J3KJvx","vH4c2c","4xvmHx","141Jcc","v2mYKK","mx3vYH","b2HH1c","cKc3HH","3H12cH","4b4vm2","HbJHKK","mbmJmY","vcxHKm","Km22Yb","H1H4JJ","3H1YHK","m4xbmJ","J3vmJc","vK2cKv","HvYJcK","421223","J1mKY3","mvcJHJ","cmvbcY","14JvHH","Y3m214","xc3bHH","mYKxvY","Hm3HHb","KvHHcY","xHxv4x","Yx1KcH","bx24HJ","xx2b32","4Y4vYc","KKvcb3","cY2vY3","mxc2cx","4142xb","33mHJ1","Hc4Jmc","v1cvY3","Jv323m","31mHxK","x344vJ","42Hcmm","Hc13JJ","mJJ3mc","mHbmvJ","JHH21x","K3x3Hv","cHm12c","bKbKH4","Y2HYvx","b2cm3v","11Kmx1","YYYH4m","xHYv1c","3v2HJY","bHxKcH","4J2cxc","KY2vKY","mvb2vv","HK4m3H","xmHb24","HvxY42","JbY4Jx","3KxYvm","H13cJm","Hmm3HH","cHHHvm","Yxc3cH","1m2K3H","HvJJ4v","K1H4cb","v3m21v","YJbJ4H","4JH1HH","mJbcx3","H1bHY3","HmJm14","bJHcHc","HH23xY","J2m1bH","xm4JHH","K1vm3H","3JJKH2","YYHHcK","HK2H3J","bcYvH1","bYcKvc","24bcH3","cH3x42","Hbmbvm","3YHJx1","cY1Hb3","Y4YYcH","b3x1bx","Hbbmv2","21v3YH","YvcJ2b","HHYb3c","cHcJ4H","xmHx2H","4cx2KH","bmvcKv","x4H42x","vHHvJY","bbc3vK","YxbK31","Kxbx2m","2mb1K3","HH1321","cmHv1x","2H1x4Y","2m1K1m","cJHHHc","YHKxmv","YvxbYH","cc2YJ4","4b4H1x","3H1bH4","HbcxmH","4KY3xH","Y4J1v2","3vKbcb","12mmvm","mHJ4cc","4YY4KJ","mYKcH2","H31JmY","1mx3Hc","Jmm2xJ","x1H4xx","bHvHbb","b3vH42","vc14Kb","H2K4Jb","22KmbH","HH1x4b","13cHK2","Y2H31Y","Jvmx1J","2mmK1m","231HJJ","KHHYx1","x43Jm3","b1Kmxm","YxmmHx","4YcH2J","4JKvKJ","1243m2","3vYmcJ","m2KH2x","YKJHYK","1YJ1xx","4HHx23","4mbKY4","KxH1cb","cm3Jvb","c2J4mm","JYHKKv","x2xJmv","H42b1v","vHYbYK","bmYx34","HKcKbK","x4KbH1","bv3vbK","Hm41xY","2cYcJ1","JvcH2m","J14cYc","vv3Jmv","mm4m1H","H1b2vm","bmxY4c","v4J33Y","cKvcH1","Y4x23H","J4K4Yv","Hbxv21","2H1xbx","HKK31v","H34xHH","JccHJJ","bHmJKb","2vHJ13","HYKJHJ","KxH4H4","Kxc43v","bvH44b","Km44HJ","cHvHJx","cHcHmH","YbbKmv","vJvHKx","3H22mH","YH3mHK","xbJH14","JbHvH4","J1H41b","bm2mYY","cH4xKx","YH11xx","3Hm41x","m4xxHJ"]

Dari data diatas ada sekitar 1000 data, nantinya tiap data yang ada di dalam array tersebut akan saya masukkan ke tabel yang kita buat diatas. Nah, kebayang kan kalo kita nanti harus masukin data yang banyak banget itu ke tabel yang kita buat tadi, gak mungkin kalo kita insert data diatas satu per satu lewat phpmyadmin. Untuk itu kita bisa pakai script di php untuk insert data yang banyak tadi ke dalam database.

Kode PHP untuk insert banyak data

Mari kita buat file php baru untuk menampung kode kita, beri nama misalkan index.php, lalu sebelum kita melakukan insert data kita harus membuat sebuah koneksi dulu ke database yang ada. Tambahkan baris kode berikut ke index.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Konfigurasi akun database
$dbHost     = "localhost";
$dbUsername = "root";
$dbPassword = "root";
$dbName     = "belajar_input_banyak_data";

// Membuat koneksi ke database
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

// Cek apakah koneksi berhasil
if ($db->connect_error) {
    die("Connection failed: " . $db->connect_error);
}

Pada kode diatas kita membuat sebuah koneksi ke database, pastikan konfigurasi database disesuaikan dengan database yang sudah dibuat, lalu kita menyimpan hasil koneksi ke variabel bernama $db. Kode selanjutnya kita tinggal menyiapkan sebuah statement atau query ke mysql kita. Tambahkan kode berikut ke index.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$sql = "INSERT INTO tiket (kode) VALUES ";
foreach ($data as $row) {
    $sql .= "('" . $row . "'),";
}
$sql = rtrim($sql, ',');
$insert = $db->query($sql);

if ($insert) {
    echo "Data berhasil disimpan";
} else {
    echo "Error: " . $sql . "<br>" . $db->error;
}

Pada kode baris pertama kita menyiapkan sebuah query dan menyimpan ke dalam variabel bernama $sql setelah itu pada baris ke-2 kita melakukan perulangan untuk menambahkan data apa saja yang akan kita insert ke database. Nah, disini nantinya query sql kita terbentuk, setelah perulangan ini berjalan query kita akan menampung 1000 data yang ada tadi yang kita simpan di variabel bernama $data. Kode pada baris ke-6 akan meng-execute query yang sudah kita siapkan tadi.

Kode PHP kita akan terlihat seperti ini index.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
$data = ["3Ym1Kb","4J1cvK","HKKYmb","mHY1YH","x2bc31","c4c43c","xJ2KH1","vHJ2v3","JmYYJb","2v4JKJ","2x1mm2","HKHcK1","cx4JJm","cYYx1x","b4b21m","bvxxm4","2Hm331","bv3YxH","K132HK","4HHKvx","Hv341H","bH1J1H","vvJ1mY","4xH2Hm","cHb33H","vxJ1HY","24H1vH","Hcbvm1","4Hvx31","mKKxmJ","vYKb4H","m3bxx3","H334HJ","1KYKbm","m2v4KY","HmKHJH","Kbvm2m","cH33c4","2YHHYH","xJ34Kc","2YY11K","1cH2bm","b23m3H","2YvHYx","2JKHK4","KvcYcc","HmbHJc","YYJ133","vY1cY2","YvmYYK","K2Y34H","cKHJxH","4mmH4K","cJmJ1m","H2b221","mKc32x","H2v2K1","2H3HKK","c13HHb","JJYxxc","JH11mJ","YbH11K","HYm3HY","HKY1mx","4KY4K1","vm43xc","xv4Kmc","KH242b","3c4cJY","bHJ31c","vHJvKY","b2vJHY","HHHxbY","m3cHcv","Jb2H1m","KYYYYH","Jmmmvx","2b4Hvc","Y43cYH","x221vJ","Yb32Hc","YbYxKm","KHYKK3","YK1bv4","HKK34H","xHY1JY","v3c4vb","K2xmYK","xJvcxm","144cYJ","YHH1mJ","Y2Hb4J","213H1J","bm422K","3bJYmm","H3324c","vJvJ3H","HmJ2J4","4bvv13","KvcYY2","HmJHxK","142122","mYvxx4","1J3433","14KY24","v4c1b4","J1v2mx","b421x2","x3v23K","Jm23m4","HvHJ2H","22333K","4b22cx","KJx14J","HKH322","4cHYx2","3bcYbb","x3x2Hx","HvH2x3","bHc3Jv","bHKKcJ","xHHc3m","4bH4x1","43bbY4","4K1Ym1","bKHH3v","2KHHxb","cHK12H","Yvxvcb","1132vb","cvm4J2","v1xKJH","Hmmx4Y","xmx2Hm","cHYbYc","1cb3Y3","b1c3J4","xv4Hxc","HHJ4Hc","c34mmK","JbxKHK","cxKxv1","1vv4mc","13HKvK","xYYJJ3","bmxmHc","HK2b1H","421ccv","Jv44KY","2vJvY2","bH1vH3","xx43YY","31c13b","JccJ2H","2bKv31","J21bb3","KKv2xY","YJH42v","xmHHbY","31Y2m3","221cc3","ccxbbY","K2c42J","bxmKKb","YvJHK2","vH4Hv2","42KYH3","1ccHcH","H4Yv2m","KvY4cb","131b3J","v43mYH","KHHJvY","HHbKvH","K1Y43c","Y4KKm1","mKmcKH","1cHHYb","J1m13H","3J1J4b","Kx34K4","4HYHbb","2JxJbK","mbbxxx","2mb3K3","c4JYHY","4Y43K2","xmJc3H","bcmmxc","mYvcc2","c4HvHH","Kvm32m","K4mcYJ","442JJ2","Y3vxHH","24KJxH","ccxH2K","Ym1H4K","JH2mHc","2JxKx4","c33Hcx","HKxmmY","JxHH3v","3m14x4","3mH14c","x3KcYY","JY2J3b","cb22JY","m2HHHv","Hb2J2H","1x44bH","cx4xY3","cJ3m23","v1vvvH","YJcbvK","HvvxYm","4v32H3","vcJmK2","YHm31H","bHm4v1","bvH4xv","YKJm33","K3KJcx","b3Y1H1","1b3m3x","KmH122","Jbbm4Y","HHJKv3","Hb4J3m","m2YvK2","bHvYYH","K4J2cY","JY1H4m","xv4xJ3","J2124m","xbHKc4","HHYHx4","YJbx3H","HHbKc2","mxbxxc","cmJbJ1","bJxH44","c3x42K","KvJJHm","31vJ31","4b44Hx","H22mm4","vJ31YH","xbbJH2","1H4cH3","m1KKb3","1K4c4H","41cK4c","JvcKv1","HY11v4","2xv3Yx","YHxm1H","3YbYHJ","4xKJJY","3222Yb","1Kb2Yv","HJ42H1","x31bHm","xvmbb3","K4bvK3","ccxYvm","2xxJ2H","KvxJ2H","3Jx2v1","cbmJ22","xv3c4b","mbHxYc","mH2x3c","Hb1v24","HJxHvK","KKmmY3","HHm3mH","xvcx1v","2xHcvK","YYxHxJ","3x3Ymb","J1ccHH","Ym3cb3","4HHbHv","x4mKv3","13HHYH","xHcJJ4","1HJ4mb","H132c2","xHHYKb","bcHJYY","HHJHHY","m4xvvJ","mb21vc","cm3bJ2","YHH4K4","2bxcKH","bxHv2m","2HYHYm","b4Y4cJ","vHmKxK","HH4Yc2","b1cHKH","HcJmm4","JYm43J","b21x4K","xJ413K","bJxHvb","YmKK13","3m3cH1","1bK24x","HHYJKH","1xxHHm","YKH1bK","HYHHHb","42HH1H","vvYx2c","mb4cHK","4KKx2H","1bm2cm","b1YxKH","vv411H","H3c1b2","bcHJHJ","32H1vc","J2J1HH","Y4bHKx","2cbv44","KcHcKY","bJmJ4m","bx2Jmm","bm4mxb","3mJKb1","v3xbc2","xm4Hm3","1HbHH4","bJbYH4","mmHxxx","Hxv1Hx","Jc34JH","1YcHKH","4Hbv1J","xY3cvY","b2cv4H","vxm4H4","xKcHKY","1mxmK3","YYcH2H","2JmH3H","KHcvmH","cH4mY3","mHHHHH","K2v4HH","Jbm22m","cH122K","Hx4vxH","m4m442","vcY2xv","YxcKmK","4K1cYH","vKK2Hm","3b4mbc","HK2vJK","1m34HH","1mJmHJ","YY1vcx","vbxHJH","H3Y4K1","KJcmYm","3Y444K","YH4mvc","4xxK3v","JH1JKH","v2K323","H2JbvH","1vc31H","b2mvJK","cJ42J2","mHJxH2","Y11mmJ","vmx1bJ","x13JJJ","4KHHHK","x1HH2c","bccxb1","124J3x","JYKHbY","cv4cJv","4c2HH4","3vJ3Hb","4bbmc2","Ym23YJ","Hvvc1H","cH1vY4","vHvK1J","v11m1H","J2mHJJ","3v4Hc1","cvHYHb","x43cxx","YHx1Ym","vxYHmK","v41c32","JJ232J","HKK1Hx","Y322YK","vmKH2x","YcHYHx","4xv1cb","mHmHHv","vJ21c3","Jxm2YH","1JHv4H","bYmvcx","vcHJJm","13vJc1","2KJxY4","3mv4KH","YHxmbm","Y1H23x","vv4v1K","Km3KKm","JJb2Kc","KHxHJH","13vb2x","YK44J1","m3b2HH","vm4H4v","KJxKxJ","2J4HJm","vvJHHK","b3b4HJ","4cbHY3","vH3YvJ","HbH3HK","1c4b2m","mHcmK3","24mH2b","432KmY","HKv2Ym","K1H1xY","bx3vm1","mKY32v","2KKKbH","HYx41x","xcHKH3","31HH2Y","KJbbYb","vHvHvK","H2cYKm","v1xcHm","c424vx","1bKYv1","Y4H33v","Ybmc4Y","K3H3Kb","vv14bK","44vmb1","HK3bHK","JKxc1v","4mHHx2","2cxJY2","2J33Yc","bcbb31","xH1KHx","xKmvc4","44Yvvm","3xmHm1","2xH2c2","m31vxJ","HY4KHK","2b412b","m23c1H","b1mm4Y","HKYvc2","bvbxYH","xJ1Hxb","cxH1KK","HY4vmx","YH2c2H","xH41xJ","41YHHm","HvYY4v","221324","mc2YJJ","vHb131","YYYJ2J","1c1cK2","22cKv3","3JHcmv","Hb1Y33","11HHmK","12Jxxm","42mxH4","KxvH34","1Hc4b1","HH24JH","1cKH43","cvKmbH","2HcmY3","Hxx4m2","3cY1HJ","YxYx14","Kbvbcb","32HxcY","4H43YK","1KJHmK","33vcHx","2cH44c","c23vHm","3Y232H","mJH4mx","KvYKJx","xYcbY3","v1b22b","K21YHb","xKcH13","Hmx44m","JcH1xH","vKbb33","cJx1c2","HcbmY4","H1Y1HJ","KmvKYm","JHbJcm","cbYKY2","KxvK3Y","Kb3cYx","m1J2KJ","cYmm4b","mKJcvc","cJJHb1","KYKcHJ","2H3vJ1","22b1Y4","YxJH41","JxYc33","cJvmH4","2HbK32","xccHKH","m2cm3c","KHb4c2","ccJxb3","mmx2bY","Y2HbHb","v3KJJH","K1J4Kb","xYv3HH","31H1J3","x3b1xH","2K4m42","bHcm24","213Kcb","JJ1x44","12vcK3","31cJK2","x2mKx1","H3H1Jv","KxHJHH","1mY2KK","bHmmbm","m3Hcx4","bbJm1b","cbvmx3","HK4HvK","H1x11K","H2bm2Y","c4mvbc","cxmJYK","JJJK12","Hbm3bJ","x1mHxH","HbK32v","2J2mxv","1c3KJ1","Jv31H4","Kbm4bK","cHvcbx","3bmHmH","4KJYbm","J4HHvH","cx3JxH","KmHx2K","cvcc13","Jx233c","YH1J11","JHHcHb","J2vv3K","xKcHm4","xm4bvm","mK1H1J","mvxKbK","xK3JJH","b4JK4x","H41c43","m21m3H","vx1b1m","2mmmvY","vbvx4H","KH42K4","44mJ4c","3HHvm2","mxK4mb","Y3mK4v","mcJ3Hc","c2bb23","bK2xHY","221HKm","1xvm2m","b3cv3m","4cvH3v","vJKxK2","xbvmx2","Kvv24H","HmvHm2","12Yxbv","1Y1JcH","Y1HKHc","vHKKJ3","2m1H1x","bx44J3","4b24Hv","Y2K1K3","J2HYHH","3cxvmx","2KK2vK","xb133v","bbmm2v","1v33Jv","22vvY3","1Kv4vv","bb2vm2","b4mHY1","cbxmH1","HJ4313","vcYYKb","JHHmmH","mcJHbH","YH2mcJ","3x1xYx","Hb41cK","4HH1K2","b2YK2H","41bbJH","JHH2Hm","HK4144","H2Jmbb","bKcc12","2mvYmH","vxbv24","1c2vmx","JYvxcm","bb1cHH","HJbH4Y","JHKbxJ","HJvbx3","1vm3K3","3442bc","4YcHm2","4JJ2Hm","v4K3m4","2JxHcY","KJ3bKY","2YY3mH","4Ycc2x","KHJ1HH","Kx2242","YmvJ2c","b122cJ","H214Hm","Y4HxbY","1K4xKH","HmvHH3","4mbmHJ","H31HcK","HcJ1Yc","42mmHc","J42mJ4","v1Y4c3","4H1mvx","KKx1vm","xJH24m","mbKvKv","xY1vJv","Yb2YmH","c2mJc3","Kmc14c","3c41YY","cJKbHc","42m4m4","2c2KJb","3HmvHK","Y2m1bH","HH1x2m","bvHmK3","cYxJJ3","Y1cYKx","mv2cJc","mcxHmc","b4cc4x","1b132H","K2bYHK","3Y2xbK","bHJJvJ","Hx34H4","cYm4v2","2J3HHK","mv1YbY","Jm2m2H","c23cmY","mHbmKm","K1vJ3x","2m3H34","1HY42H","KbYH2Y","J4xKHx","x4HJ2c","xKJY43","Y2c31m","KH222H","JKKKbH","YJc2c4","mv3H1J","v43xKH","vYJ4bm","Hb4mvc","KvmKbm","YvJ134","cYv3bb","Y3144Y","3YYKbY","HY3bvH","bbv1b2","YY13KH","cH3YYb","HHxK34","HYxm1v","c2xmmc","2YY3Hm","J4YYx3","3xmmHY","mmxb33","mJxvKb","H1JmKm","HvJbbc","YJc1mb","cHKKcH","33H12J","HY2YxY","HmHJHb","b32xJ2","4b2H24","HYJHHK","xYcKHc","YKK2cx","214JvJ","YHmm3v","H2mx2H","3vHx4K","HHHx2v","xcHmxb","Jm43cx","JHKcH1","vJ3cvY","K3b11b","4KJxc2","Y4KmK3","HJvmx2","b1mK2b","YHH2Jm","vHmKKv","JJHKbK","c31bc4","JbbKHK","YmHb44","b14H4H","KbHHmv","bH1bb3","vHm3xx","mH1bmc","41H3v4","3vHYcb","HxHK3J","KYHHm2","b1YKKY","KvHKvJ","xbv23x","HKKJJ3","bK243x","KHHJJb","mKc321","xKHH33","3mbHbx","J3KJvx","vH4c2c","4xvmHx","141Jcc","v2mYKK","mx3vYH","b2HH1c","cKc3HH","3H12cH","4b4vm2","HbJHKK","mbmJmY","vcxHKm","Km22Yb","H1H4JJ","3H1YHK","m4xbmJ","J3vmJc","vK2cKv","HvYJcK","421223","J1mKY3","mvcJHJ","cmvbcY","14JvHH","Y3m214","xc3bHH","mYKxvY","Hm3HHb","KvHHcY","xHxv4x","Yx1KcH","bx24HJ","xx2b32","4Y4vYc","KKvcb3","cY2vY3","mxc2cx","4142xb","33mHJ1","Hc4Jmc","v1cvY3","Jv323m","31mHxK","x344vJ","42Hcmm","Hc13JJ","mJJ3mc","mHbmvJ","JHH21x","K3x3Hv","cHm12c","bKbKH4","Y2HYvx","b2cm3v","11Kmx1","YYYH4m","xHYv1c","3v2HJY","bHxKcH","4J2cxc","KY2vKY","mvb2vv","HK4m3H","xmHb24","HvxY42","JbY4Jx","3KxYvm","H13cJm","Hmm3HH","cHHHvm","Yxc3cH","1m2K3H","HvJJ4v","K1H4cb","v3m21v","YJbJ4H","4JH1HH","mJbcx3","H1bHY3","HmJm14","bJHcHc","HH23xY","J2m1bH","xm4JHH","K1vm3H","3JJKH2","YYHHcK","HK2H3J","bcYvH1","bYcKvc","24bcH3","cH3x42","Hbmbvm","3YHJx1","cY1Hb3","Y4YYcH","b3x1bx","Hbbmv2","21v3YH","YvcJ2b","HHYb3c","cHcJ4H","xmHx2H","4cx2KH","bmvcKv","x4H42x","vHHvJY","bbc3vK","YxbK31","Kxbx2m","2mb1K3","HH1321","cmHv1x","2H1x4Y","2m1K1m","cJHHHc","YHKxmv","YvxbYH","cc2YJ4","4b4H1x","3H1bH4","HbcxmH","4KY3xH","Y4J1v2","3vKbcb","12mmvm","mHJ4cc","4YY4KJ","mYKcH2","H31JmY","1mx3Hc","Jmm2xJ","x1H4xx","bHvHbb","b3vH42","vc14Kb","H2K4Jb","22KmbH","HH1x4b","13cHK2","Y2H31Y","Jvmx1J","2mmK1m","231HJJ","KHHYx1","x43Jm3","b1Kmxm","YxmmHx","4YcH2J","4JKvKJ","1243m2","3vYmcJ","m2KH2x","YKJHYK","1YJ1xx","4HHx23","4mbKY4","KxH1cb","cm3Jvb","c2J4mm","JYHKKv","x2xJmv","H42b1v","vHYbYK","bmYx34","HKcKbK","x4KbH1","bv3vbK","Hm41xY","2cYcJ1","JvcH2m","J14cYc","vv3Jmv","mm4m1H","H1b2vm","bmxY4c","v4J33Y","cKvcH1","Y4x23H","J4K4Yv","Hbxv21","2H1xbx","HKK31v","H34xHH","JccHJJ","bHmJKb","2vHJ13","HYKJHJ","KxH4H4","Kxc43v","bvH44b","Km44HJ","cHvHJx","cHcHmH","YbbKmv","vJvHKx","3H22mH","YH3mHK","xbJH14","JbHvH4","J1H41b","bm2mYY","cH4xKx","YH11xx","3Hm41x","m4xxHJ"]

// Konfigurasi akun database
$dbHost     = "localhost";
$dbUsername = "root";
$dbPassword = "root";
$dbName     = "belajar_input_banyak_data";

// Membuat koneksi ke database
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

// Cek apakah koneksi berhasil
if ($db->connect_error) {
    die("Connection failed: " . $db->connect_error);
}

$sql = "INSERT INTO data_kode (kode) VALUES ";
foreach ($data as $row) {
    $sql .= "('" . $row . "'),";
}
$sql = rtrim($sql, ',');
$insert = $db->query($sql);

if ($insert) {
    echo "Data berhasil disimpan";
} else {
    echo "Error: " . $sql . "<br>" . $db->error;
}

Setelah itu coba jalankan file php kita tadi, maka jika tidak terjadi error akan tampil "Data berhasil disimpan" dan akan ada 1000 data di tabel database kita.

Data Berhasil

Data pada phpmyadmin

Dibangun dengan Hugo
Tema Stack dirancang oleh Jimmy