Skip to content

Instantly share code, notes, and snippets.

@dwihujianto
Created October 8, 2015 05:18
Show Gist options
  • Save dwihujianto/5aa7fcdbf6715ae2b5b1 to your computer and use it in GitHub Desktop.
Save dwihujianto/5aa7fcdbf6715ae2b5b1 to your computer and use it in GitHub Desktop.
Insert Batch
<?php
$names = array(
'Wiro',
'Sableng',
'Joko',
'Sembung',
'Iwan',
'Tono',
'Cahyadi',
'Panji',
'Saras',
'Ironman',
'Suharno'
);
$cities = array(
'Yogyakarta',
'Ponorogo',
'Malang',
'Magetan',
'Manukwari',
'Lampung'
);
$query = "INSERT INTO anggota (name,city,dateOfbirth) VALUES";
$totalInsert = 100;
for ($i=1; $i <= $totalInsert; $i++)
{
$getName = rand(0,10);
$getCity = rand(0,5);
$getDay = rand(1,31);
$getMonth = rand(1,12);
$getYear = rand(1990,2000);
if ($i<$totalInsert)
{
$query .= "('{$names[$getName]}','{$cities[$getCity]}','$getYear-$getMonth-$getDay'),";
}
else
{
$query .= "('{$names[$getName]}','{$cities[$getCity]}','$getYear-$getMonth-$getDay')";
}
}
$conn = mysqli_connect('localhost','root','','database');
$result = mysqli_query($conn,$query);
if ($result)
{
echo "All data has been saved \m/";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment