-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12-inserting-user-records.php
33 lines (28 loc) · 1.4 KB
/
12-inserting-user-records.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
<?php
$conn = require '12-connection.php';
$sql = "
INSERT INTO users (name, email, info) VALUES ('Antonio', 'antonio@phpfullstack.com.br', 'Tech enthusiast and music lover'),
('Thais', 'thais@phpfullstack.com.br', 'Creative thinker, problem solver'),
('Anthony', 'anthony@phpfullstack.com.br', 'Passionate about sustainability and innovation'),
('Mariah', 'mariah@phpfullstack.com.br', 'Avid reader and lifelong learner'),
('Esther', 'esther@phpfullstack.com.br', 'Fitness fanatic and foodie'),
('Vitória', 'vitoria@phpfullstack.com.br', 'Explorer, dreamer, passionate creator');
";
if (!$conn->multi_query($sql)) {
echo "Error inserting records: {$conn->error}\n";
} else {
echo "Records inserted successfully \n";
// Consume all pending results to free the connection
while ($conn->next_result()) {
//// If there is a result, we can fetch it or simply ignore it
if ($result = $conn->store_result()) {
$result->free();
}
}
}
$query = "SELECT * FROM users";
$result = $conn->query($query);
while ($row = $result->fetch_assoc()) {
echo "ID: {$row['id']} - Name: {$row['name']} - Email: {$row['email']} - Info: {$row['info']} \n";
}
$conn->close();