fixed mysql query for history

This commit is contained in:
2024-07-25 09:21:54 +02:00
parent e4427c9eac
commit 500486ba38

View File

@@ -24,9 +24,8 @@ class WarehouseHistoryModel {
public static function create($data) {
$FronkDB = FronkDB::singleton();
$db = $FronkDB->link;
$sql = /** @lang text */ "INSERT INTO `WarehouseHistory` (`table`, `row_id`, `key`, `old_value`, `new_value`, `note`, `user_id`, `create`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute([
$dataArr = [
$data["table"],
$data["row_id"],
$data["key"],
@@ -35,9 +34,16 @@ class WarehouseHistoryModel {
$data["note"],
$data["user_id"],
$data["create"]
]);
];
return $stmt->insert_id;
$sqlValueStr = "(" . implode(", ", array_map(function ($item) use ($db) {
return "'" . $db->real_escape_string($item) . "'";
}, $dataArr)) . ")";
$sql = /** @lang text */ "INSERT INTO `WarehouseHistory` (`table`, `row_id`, `key`, `old_value`, `new_value`, `note`, `user_id`, `create`) VALUES $sqlValueStr";
$db->query($sql) or die($db->error);
return $db->insert_id;
}
/**
* Retrieves an array of WarehouseHistoryModel objects by row ID.