I'm trying to do that in PHP.
This code should insert 500000 rows in users table and after each row should print the value of $C(last for loop counter) in new line but it doesn't work properly. It inserts rows correctly but it doesn't print $c after inserting the row. Why doesn't it work like that? And how can i update this code to work like i want?
Thanks all in advance
<?php
$handler = new PDO("mysql:host=localhost;dbname=test",'root','');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
function randomname(){
$len = mt_rand(20,50);
$string = "";
for($i=0;$i<$len;$i++){
$ch = mt_rand(32, 122);
if(($ch == 32 && $string != "") || ($ch >=97 && $ch <=122))
$string .= chr($ch);
else
continue;
}
return $string;
}
function randomemail(){
$len = mt_rand(7,15);
$string = "";
for($i=0;$i<$len;$i++){
$ch = mt_rand(32, 122);
if(($ch == 32 && $string != "") || ($ch >=97 && $ch <=122))
$string .= chr($ch);
else
continue;
}
if($len < 10)
return $string."@hotmail.com";
else
return $string."@gmail.com";
}
ini_set('max_execution_time', 500000);
for($c = 0; $c<=500000;$c++){
$name = randomname();
$mail = randomemail();
$query = $handler->query("insert into users(name, mail, password, created_at) values('$name', '$mail', '123132', now())");
echo "$c</br>";
}
Aucun commentaire:
Enregistrer un commentaire