-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate_db.php
39 lines (32 loc) · 1.5 KB
/
populate_db.php
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
30
31
32
33
34
35
36
37
38
39
<?php
// Database connection settings
$host = 'localhost';
$dbname = 'mydb';
$username = 'root';
$password = '';
try {
// Connect to the database
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Prepare the SQL query to update the table
$stmt = $pdo->prepare("UPDATE donations SET name = :name, email = :email, phone_number = :phone WHERE id = :id");
// Predefined arrays of Indian names
$names = array('Rahul Sharma', 'Priya Patel', 'Suresh Kumar', 'Anita Gupta', 'Amit Singh', 'Deepika Sharma', 'Ajay Yadav', 'Pooja Shah', 'Manoj Kumar', 'Kavita Verma');
// change the rumber with total rows in "donations" table
for ($i = 1; $i <= 172; $i++) {
// Generate random Indian name, email, and phone number
$name = $names[array_rand($names)]; // Select random name from the predefined list
$email = strtolower(str_replace(' ', '.', $name)) . '@example.com'; // Generate email based on name
$phone = '91' . mt_rand(6000000000, 9999999999); // Generate random Indian phone number
// Bind parameters and execute the query
$stmt->bindParam(':name', $name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':phone', $phone);
$stmt->bindParam(':id', $i);
$stmt->execute();
}
echo "Data updated successfully!";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>