Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQLi bind_param UPDATE不能使用空值_Php_Mysql_Mysqli - Fatal编程技术网

Php MySQLi bind_param UPDATE不能使用空值

Php MySQLi bind_param UPDATE不能使用空值,php,mysql,mysqli,Php,Mysql,Mysqli,我有下面的MySQL查询,它看起来很好,但在一个变量为空时不会更新表 $stmtEmploymentDetails = getDB()->prepare( 'UPDATE EmploymentDetails SET BranchOffice=?, EmploymentDate=?, EmploymentStatus=?, EmploymentType=?, OrdinaryHours=?, JobClassification=?, ManagmentGroupID=? WHERE

我有下面的MySQL查询,它看起来很好,但在一个变量为空时不会更新表

$stmtEmploymentDetails = getDB()->prepare(
    'UPDATE EmploymentDetails SET BranchOffice=?, EmploymentDate=?, EmploymentStatus=?, EmploymentType=?, OrdinaryHours=?, JobClassification=?, ManagmentGroupID=? WHERE EmployeeID=?'
);
和绑定参数

$stmtEmploymentDetails->bind_param(
    'ssiiisss',
    $branchOffice,
    $employmentDate,
    $employmentStatus,
    $employmentType,
    $ordinaryHours,
    $jobClassification,
    $managmentGroupID,
    $employeeID
);

$stmtEmploymentDetails->execute;
我也尝试过使用COALESCE,但是我假设的值是空的而不是空的

$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=?'
);
同样的方法在使用

$stmtEmployeeProfile = getDB()->prepare(
    'UPDATE EmployeeProfiles SET AKAName=? WHERE EmployeeID=?'
);

但在该查询中,始终提供值。
有人知道问题出在哪里吗?

您是否在查询周围放置了错误报告以查看实际发生的情况

if ($stmtEmploymentDetails = getDB()->prepare(
'UPDATE EmploymentDetails 
 SET BranchOffice=?, EmploymentDate=?, 
 EmploymentStatus=?, EmploymentType=?, 
 OrdinaryHours=?, 
 JobClassification=?, 
 ManagmentGroupID=? 
 WHERE EmployeeID=?')) { 
    $stmtEmploymentDetails->execute(); 
 } else {
 echo "Failed prepare statement" . $this->conn->error . $this->conn->error;
 }
我希望这能对你有所帮助,当你有这个错误的时候,你就可以从这个错误开始工作了。可能是拼写问题,或者您没有正确检查值是否为空。这样做的方法是一个简单的isset语句,例如

if (isset($stmtEmplotmentDetails)) {
// do something 
} else {
$stmtEmplotmentDetails = 0; // or default value e.g. "N/A"
}

另外,如果您检查了数据类型是否与数据库正确对应,那么在绑定参数查询中就有字符串和整数。它们是否与数据库中的数据类型匹配?

如果可能,您能否显示即将出现的错误?只需更新问题以澄清问题。它将在没有警告的情况下执行,但不会更新表。我将研究添加一些与N/A类似的内容,看看这是否解决了问题。如果没有默认值,我会一直抱怨,只需确保在每种情况下都有正确的检查,例如null、empty、,夸大的或不正确的value@JedHodson如果您已经解决了问题,请告诉我:我执行了错误检查,问题是没有返回任何错误。查询将成功执行,但不会更新行。我现在正在添加空值检查,所以我将在完成后报告。
if (isset($stmtEmplotmentDetails)) {
// do something 
} else {
$stmtEmplotmentDetails = 0; // or default value e.g. "N/A"
}