I’m using php/mysql and am trying to run an INSERT query or an UPDATE query.
I want to run an INSERT if it is a new record, and an UPDATE if its not a new record.
So im guessing the code is something like
$ac_unit_id = 7;
$x_coord = 3;
$y_coord = 2;
$room_id = 1;
//Im guessing if the FK ($ac_unit_id ) exists in the object_location table we only run an update, but if the FK is not set, dont we need to create it?
if() {
$sql = "INSERT INTO object_locations (type,room_id,ac_unit_id,x_coord,y_coord) VALUES ('ac_unit',".$room_id.",".$ac_unit_id.",".$x_coord.",".$y_coord.")";
} else {
$sql = "UPDATE object_locations SET room_id = ".$room_id..", ".$x_coord = ".$x_coord.", y_coord = ".$y_coord." WHERE ac_unit_id = ".$ac_unit_id.";
}
I was kind of intimidated to jumping into PDO, but it really seems not to be bad.
I was trying one of those ON DUPLICATE KEY UPDATE queries and this happened.