Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try
- {
- $pdo = new PDO('mysql:host=localhost;dbname=s88114_fitness', 's88114', 'upasasedu');
- $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- //deklaracja ilosci petli
- $liczba2=2;
- for ($i=0; $i<$liczba2;$i++)
- {
- //random cena
- $kod=rand(1000,9999);
- //end random cena
- //random string
- $length1 = 40;
- $chars1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $ulica = substr( str_shuffle( $chars1 ), 0, $length1 );
- $length2 = 30;
- $chars2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $miejscowosc = substr( str_shuffle( $chars2 ), 0, $length2 );
- $length3 = 30;
- $chars3 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $powiat = substr( str_shuffle( $chars3 ), 0, $length3 );
- $length4 = 30;
- $chars4 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $gmina = substr( str_shuffle( $chars4 ), 0, $length4 );
- //end random string
- //insert into database
- $liczba = $pdo->exec("INSERT INTO adres_zamieszkania (id_test, ulica, miejscowosc, kod_pocztowy, powiat, gmina )
- VALUES(NULL,'$ulica' ,'$miejscowosc', '$kod' , '$powiat', '$gmina')");
- }
- if($liczba > 0)
- {
- echo 'Dodano ' .$liczba2. ' adresów zamieszkania!';
- }
- else
- {
- echo 'Wystąpił błąd podczas dodawania rekordów!';
- }
- }
- catch(PDOException $e)
- {
- echo 'Wystąpił błąd biblioteki PDO: ' . $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement