Advertisement
RahmanIEN

Generate Data Dengan Faker

Jun 23rd, 2023 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | Source Code | 0 0
  1. <?php
  2.     require_once('vendor/autoload.php');
  3.     use Faker\Factory;
  4.  
  5.     $faker = Factory::create('id_ID');
  6.  
  7.     for($i=1; $i<=50; $i++){
  8.  
  9.         $nama       = $faker->name;
  10.         $umur     = $faker->numberBetween($min = 0, $max = 120);
  11.         $jenis_kelamin    = $faker->randomElement($array = array ('laki','perempuan'));
  12.         $nomor_telepon     = $faker->phoneNumber;
  13.         $koneksi    = mysqli_connect("localhost","root","","data-penduduk");
  14.  
  15.         mysqli_query($koneksi, "insert into penduduk set
  16.        nama='$nama', umur='$umur',
  17.        jenis_kelamin='$jenis_kelamin',
  18.        nomor_telepon='$nomor_telepon'");
  19.     }
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement