-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateUser.php
More file actions
29 lines (28 loc) · 849 Bytes
/
createUser.php
File metadata and controls
29 lines (28 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
$con = new mysqli("localhost", "root", "rhr5asiq1", "db");
if($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$num = 0;
while($num++ < 1000) {
$username = generateRandomString();
$favorite = rand(1,1326);
$rate = rand(0,4) + rand(0,9) / 10.0;
$sql = "INSERT INTO user(username, favorite, rate) VALUE ('$username', '$favorite', '$rate');";
if($con->query($sql) !== TRUE) {
echo "error:" . $sql . "<br>" . $con->error;
break;
}
}
echo "finished";
$con->close();
function generateRandomString($length = 20) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>