早上好,我正在拼命解决在 MySQL 5.7.19 中插入空白日期值时遇到的问题,三天后,我来到这里寻求帮助。
数据库设置为允许 NULL - 默认 NULL,有时会填充前端字段,但更常见的是不是空值。
弹出错误:
Cannot execute SQL statement: Incorrect date value: '' for column 'signedupdate' at row 1
插入
$lastInsertId = $this->GetConnection()->GetLastInsertId();
$sql = sprintf("INSERT INTO tbl_lead (client_id, signedupdate, plan_type) VALUES(%d, '%s', '%s');", $lastInsertId, $rowData['signedupdate'], $rowData['plan_type']);
$this->GetConnection()->ExecSQL($sql);
更新
$sql = sprintf("UPDATE tbl_lead SET signedupdate = '%s', plan_type = '%s'WHERE client_id = %d;", $rowData['signedupdate'], $rowData['plan_type']);
$this->GetConnection()->ExecSQL($sql);
有人能看出我哪里出了问题吗?
最佳答案
在执行查询字符串之前尝试回显查询字符串,并在phymyadmin中复制/粘贴回显的查询并检查查询中的错误
$lastInsertId = $this->GetConnection()->GetLastInsertId();
$sql = sprintf("INSERT INTO tbl_lead (client_id, signedupdate, plan_type) VALUES(%d, '%s', '%s');", $lastInsertId, $rowData['signedupdate'], $rowData['plan_type']);
echo $sql;
$this->GetConnection()->ExecSQL($sql);
关于php - Sprintf将NULL插入mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50346160/