In PHP and MySQL we easily can insert the data in bulk or with a single query but it's always critical to updated the bulk records in MySQL table.
Here I'm going to explain how can we update the records in bulk in PHP and MySQL.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<?php
$con = new mysqli('localhost', 'root', '', 'demo');
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$query = "UPDATE test SET name = (CASE id
WHEN 1 THEN 'apple'
WHEN 2 THEN 'orange'
WHEN 3 THEN 'peach'
END)
WHERE id IN(1,2 ,3)";
if ($con->query($query) === TRUE) {
printf("Batch update successfully done.\n");
}
?>
|