Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1.  
  2. function generatestring($length = 8)
  3. {
  4.     $chars = 'abdefhiknrstyzABDEFGHKNQRSTYZ23456789';
  5.     $numChars = strlen($chars);
  6.     $string = '';
  7.     for ($i = 0; $i < $length; $i++) {
  8.         $string .= substr($chars, rand(1, $numChars) - 1, 1);
  9.     }
  10.     return $string;
  11. }
  12.  
  13. $user = 'root';
  14. $pass = 'root';
  15. $dbh = new PDO('mysql:host=localhost;dbname=test_innodb', $user, $pass);
  16.  
  17. for ($i = 1; $i <= 1000000000; $i++) {
  18.    
  19.     if ($i % 1000 == 0) {
  20.         echo "\t== Старт == \nЗапрос $i\n";
  21.     }
  22.    
  23.     $varchar = generatestring(255);
  24.     $bigint = mt_rand(10000000, 1000000000);
  25.     $text = generatestring(9999);
  26.     $longtext = generatestring(9999);
  27.     $statement = $dbh->prepare("INSERT INTO tableForTest(`varchar`, `bigint`, `text`, `longtext`) VALUES('$varchar', '$bigint', '$text', '$longtext')");
  28.     $statement->execute();
  29.    
  30.     if ($i % 15000 == 0) {
  31.         echo "Очистка $i\n";
  32.         $dbh->exec("DELETE FROM tableForTest WHERE `bigint` % 3 = 1");
  33.     }
  34.     if ($i % 10000 == 0) {
  35.         echo "Очистка $i\n";
  36.         $dbh->exec("DELETE FROM tableForTest WHERE `bigint` % 4 = 0");
  37.     }
  38.     if ($i % 54321 == 0) {
  39.         echo "Очистка $i\n";
  40.         $dbh->exec("DELETE FROM tableForTest WHERE `bigint` != 0");
  41.     }
  42.     if ($i % 1000 == 0) {
  43.         echo "\t== Конец == \n\n";
  44.     }
  45. }
  46.  
  47. echo "Финал\n";
  48. $dbh->exec("DELETE FROM tableForTest WHERE `bigint` != 0");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement