-
Notifications
You must be signed in to change notification settings - Fork 1
/
insert-into-database.php
43 lines (36 loc) · 963 Bytes
/
insert-into-database.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* insert-into-database.php
*
* @author: onirudda.odikare@widespace.com
* @created on: 6/10/18
*/
require_once "vendor/autoload.php";
require_once "database.php";
use Illuminate\Database\Capsule\Manager as Database;
$faker = Faker\Factory::create();
if (count($argv) < 2) {
print "Argument missing: " . PHP_EOL;
print "Example: php insert-into-database.php [numberOfRows]" . PHP_EOL;
exit();
}
$numberOrRows = $argv[1];
printf("Creating %d records in students table ... " . PHP_EOL, $numberOrRows);
try {
TimeTracker::start();
for ($i = 0; $i < $numberOrRows; $i++) {
Database::table('students')->insert([
'joinDate' => $faker->date('Y-m-d'),
'name' => $faker->name,
'regNo' => $faker->numberBetween(10000000, 999999999999999999),
'address' => $faker->address
]);
if ($i % 1000 == 0) {
echo ".";
}
}
TimeTracker::end();
TimeTracker::showTimeDiff();
} catch (Exception $e) {
echo $e->getMessage();
}