Advertisement
rozman50

Fills DB with garbage

Dec 5th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. <?php
  2.  
  3. DEFINE ('DB_USER', 'root'); //username
  4. DEFINE ('DB_PASSWORD', 'password'); //password
  5. DEFINE ('DB_HOST', 'localhost'); //IP/localhost
  6. DEFINE ('DB_NAME', 'dbname'); //database name
  7.  
  8. $dbc = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  9.  
  10. $ctarray = array();
  11. $vsebinaarray = array();
  12.  
  13. //število ustvarjenih tabel
  14. $st_tabel = 100;
  15.  
  16. //število stolpcev na tabelo
  17. $st_stolpcev = 50;
  18.  
  19. //šrevilo vrstic
  20. $st_vrstic = 1000000;
  21.  
  22. //STEVILO STOLPCEV st0 varchar(255)...
  23. for($i = 0; $i <= $st_stolpcev; $i++){
  24.   $ctarray[] = "st$i";
  25. }
  26.  
  27. //doda podatkovni tip stolpcu
  28. $str =  implode(" varchar(255), ", $ctarray);
  29. $str = $str . ' varchar(255)';
  30.  
  31. //st0, st1, st2 za INSERT INTO
  32. $elementi = implode(", ", $ctarray);
  33.  
  34. //stevilo ustvarjenih tabel
  35. for($l = 0; $l <= $st_tabel; $l++){
  36.  
  37.   //CREATE TABLE tab0 (id int auto_increment not null primary key, st0 varchar(255), st1 varchar(255), st2 varchar(255))
  38.   $query_create = "CREATE TABLE tab$l (id int auto_increment not null primary key, $str)";
  39.   $res_insert = mysqli_query($dbc, $query_create);
  40.  
  41.   //stevilo vrstic, ki jih ustvari (1000000)
  42.   for($k = 0; $k < $st_vrstic; $k++){
  43.    
  44.     //stevilo stolpcev (naredi podatke)
  45.     for($i = 0; $i <= $st_stolpcev; $i++){
  46.      
  47.       //izracuna 64 znakov dolgi hash (varchar sprejme 255)
  48.       $el = '"' . hash("sha256", rand(1, 1000000)) . '"';
  49.       $vsebinaarray[] = $el;
  50.     }
  51.    
  52.     //doda vejice k hashu ( hash, hash, )
  53.     $vsebina = implode(", ", $vsebinaarray);
  54.    
  55.     //INSERT INTO tab0 (st0, st1, st3) VALUES ("956707df478593e", "d2b0171b504250f0", "b3ce289cc11bda899e")
  56.     $insert = "INSERT INTO tab$l ($elementi) VALUES ($vsebina)";
  57.     $res1_insert = mysqli_query($dbc, $insert);
  58.    
  59.     //pobriše array
  60.     unset($vsebinaarray);
  61.     $vsebina = "";
  62.     $insert = "";
  63.    
  64.   }
  65. }
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement