Guest User

Untitled

a guest
Aug 11th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. require __DIR__ . '/vendor/autoload.php';
  4.  
  5. $dsn = 'mysql:dbname=db1;host=127.0.0.1';
  6. $user = 'root';
  7. $password = '(disensor)';
  8.  
  9. try {
  10. $dbh = new PDO($dsn, $user, $password);
  11. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. } catch (PDOException $e) {
  13. echo 'Connection failed: ' . $e->getMessage();
  14. }
  15.  
  16. $sth = $dbh->prepare('INSERT INTO category(category_name, category_description, category_enabled) VALUES(:category_name, :category_description, :category_enabled)');
  17.  
  18. $faker = Faker\Factory::create();
  19. $faker->seed(time());
  20.  
  21. for ($i = 1; $i <= 1000000; $i++) {
  22. $sth->bindValue('category_name', $faker->words(4, true) . " $i");
  23. $sth->bindValue('category_description', $faker->text() . " $i");
  24. $sth->bindValue('category_enabled', mt_rand(0, 1));
  25. $sth->execute();
  26. }
Add Comment
Please, Sign In to add comment