【问题标题】:Mysql table column Not be null , But column i need null in codeingiterMysql表列不是null,但我需要在codeigniter中为null
【发布时间】:2019-03-04 07:14:53
【问题描述】:

很痛苦,表列不是空值。我的表列“值”不为空。因为我需要它。这就是为什么我将它设置为不为空。当我从其他第三方同步数据时,一些值是空的并且它发生了。因此,如果 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 中将列更改为 null。

谢谢

【问题讨论】:

    标签: jquery mysql codeigniter


    【解决方案1】:

    请检查:

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

    【讨论】:

      【解决方案2】:

      您可以将其添加到您的代码中

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

      如果 $records['value'] 为空,您将在数据库中插入一个空字符串

      【讨论】:

      • 没有任何条件,任何查询或mysql表都必须做
      猜你喜欢
      • 2017-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      相关资源
      最近更新 更多