php - Sprintf将NULL插入mysql

标签 php mysql printf

早上好,我正在拼命解决在 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/

相关文章:

php - 如何在 xsl 中使用 php 变量?

c - 逗号运算符的行为

c++ - 格式化 printf (c) 等同于 C++ 中的格式化 cerr

c++ - 为什么这在 C++ 中返回零?

php - DOM 返回空对象

php - 如何使用 Google Sheets API v4 通过 PHP 在电子表格中创建新工作表或标签

MySQL:如何找出哪些表引用了特定表?

mysql - 加入+计数第二张表

php - html 图像不适合图像包装器

php - mysqli:混合 OO 和过程代码