Request your help on how to insert a PHP array of type below into Mysql with single query by avoiding the foreach loop as below query.
What would be the performance gain in we use a single query to insert vs the below query(foreach).
PHP Array
(
[0] => Array
(
[Name] => NNN1
[Type] => TTT1
)
[1] => Array
(
[Name] => NNN2
[Type] => TTT2
)
Query:
foreach ($array as $i) {
$na = $item["Name"];
$ty = $item["Type"];
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
$dc = $db->prepare("INSERT INTO allocation (`Name`, `Type`) VALUES (?, ?) ON DUPLICATE KEY UPDATE Type = IF(Type != VALUES(Type), VALUES(Type), '$ty')");
$dc->bind_param("ss", $na, $ty);
$dc->execute();
$dc->execute();
$dc->close();
}