I have the following MySQL query that appears sound but wont update the table when one variable is empty
$stmtEmploymentDetails = getDB()->prepare(
'UPDATE EmploymentDetails SET BranchOffice=?, EmploymentDate=?, EmploymentStatus=?, EmploymentType=?, OrdinaryHours=?, JobClassification=?, ManagmentGroupID=? WHERE EmployeeID=?'
);
and the binding param
$stmtEmploymentDetails->bind_param(
'ssiiisss',
$branchOffice,
$employmentDate,
$employmentStatus,
$employmentType,
$ordinaryHours,
$jobClassification,
$managmentGroupID,
$employeeID
);
$stmtEmploymentDetails->execute;
I have also tried using COALESCE
but the value (I'm assuming) is empty not null
$stmtEmploymentDetails = getDB()->prepare(
'UPDATE EmploymentDetails SET BranchOffice=COALESCE(BranchOffice=?, BranchOffice), EmploymentDate=COALESCE(EmploymentDate=?, EmploymentDate), EmploymentStatus=COALESCE(EmploymentStatus=?, EmploymentStatus), EmploymentType=COALESCE(EmploymentType=?, EmploymentType), OrdinaryHours=COALESCE(OrdinaryHours=?, OrdinaryHours), JobClassification=COALESCE(JobClassification=?, JobClassification), ManagmentGroupID=COALESCE(ManagmentGroupID=?, ManagmentGroupID) WHERE EmployeeID=?'
);
This same approach works without any problems on a smaller query with
$stmtEmployeeProfile = getDB()->prepare(
'UPDATE EmployeeProfiles SET AKAName=? WHERE EmployeeID=?'
);
and
$stmtEmployeeProfile->bind_param(
'ss',
$AKAName,
$employeeID
);
$stmtEmployeeProfile->execute();
But in that query the values are always supplied. Anyone know where the problem is?