Mysql表列不为空,但列i在编码中需要为空



这很痛苦,表列不是空值。我的表列"值"不为空。因为我需要它。这就是为什么我将其设置为不为空的原因。 当我从其他第三方同步数据时,某些值为空并且发生了。因此,如果为空,如何设置为列。

在这里我的控制器代码都可以,只需要插入,如果为 null 则也插入为空,但表列不需要设置为 null。

$sync_history = array();
$sync_history['total_sync_record'] = $records['count'];
$sync_history['module'] = $records['module'];
$sync_history['sync_time'] =  $records['time'];
$sync_history['sync_by'] = $records['user'];
$sync_history['way'] = $records['way'];
$sync_history['sync_type'] = 'Manual';
$sync_history['operation_type'] = 'Insert';
$sync_history['value'] = $records['value'];
$this->db->insert('sync_data', $sync_history);

这是问题$sync_history['value'].如果可能的话,不要在 mysql 中将列更改为空。

谢谢

请检查:

($records['value'] != null || $records['value'] != "") ? $records['value'] : "";

你可以把它添加到你的代码中

if ($records['value'] == null){
$sync_history['value'] = "";
}

这样,如果$records['value']为空,则将向数据库插入一个空字符串

最新更新