Advertisement
Guest User

Untitled

a guest
May 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2. try
  3. {
  4. $pdo = new PDO('mysql:host=localhost;dbname=s88114_fitness', 's88114', 'upasasedu');
  5. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  6. //deklaracja ilosci petli
  7. $liczba2=2;
  8.  
  9. for ($i=0; $i<$liczba2;$i++)
  10. {
  11. //random cena
  12. $kod=rand(1000,9999);
  13. //end random cena
  14. //random string
  15. $length1 = 40;
  16. $chars1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  17. $ulica = substr( str_shuffle( $chars1 ), 0, $length1 );
  18.  
  19. $length2 = 30;
  20. $chars2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  21. $miejscowosc = substr( str_shuffle( $chars2 ), 0, $length2 );
  22.  
  23. $length3 = 30;
  24. $chars3 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  25. $powiat = substr( str_shuffle( $chars3 ), 0, $length3 );
  26.  
  27. $length4 = 30;
  28. $chars4 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  29. $gmina = substr( str_shuffle( $chars4 ), 0, $length4 );
  30. //end random string
  31.  
  32.  
  33.  
  34.  
  35. //insert into database
  36. $liczba = $pdo->exec("INSERT INTO adres_zamieszkania (id_test, ulica, miejscowosc, kod_pocztowy, powiat, gmina )
  37. VALUES(NULL,'$ulica' ,'$miejscowosc', '$kod' , '$powiat', '$gmina')");
  38.  
  39. }
  40.  
  41. if($liczba > 0)
  42. {
  43. echo 'Dodano ' .$liczba2. ' adresów zamieszkania!';
  44. }
  45. else
  46. {
  47. echo 'Wystąpił błąd podczas dodawania rekordów!';
  48. }
  49. }
  50. catch(PDOException $e)
  51. {
  52. echo 'Wystąpił błąd biblioteki PDO: ' . $e->getMessage();
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement