idiorm/paris-将null写入数据库



我正在将idiorm与巴黎一起用于我的PHP项目。
我想在我的MySQL数据库中添加一些带有一些空价值的条目。
例如:

$openingtime->setBegin(null);
$openingtime->setEnd(null);
$openingtime->setDayOfWeek(1);
$openingtime->save();

数据库中的开始和末端列具有"时间"类型,它们是无效的。
异常结果

+----+-------+------+-----------+
| id | begin | end  | dayOfWeek |
+----+-------+------+-----------+
|  1 | null  | null |         1 |
+----+-------+------+-----------+

我得到的结果:

+----+----------+----------+-----------+
| id |  begin   |   end    | dayOfWeek |
+----+----------+----------+-----------+
|  1 | 00:00:00 | 00:00:00 |         1 |
+----+----------+----------+-----------+

orm :: get_last_query()说类似的话:

UPDATE `openingtime` SET `begin` = '', `end` = '', `dayOfWeek` = '1'

因此,iDiorm/paris插入一个空字符串。

有可能添加空字符串而不是添加空字符串?感谢您的帮助!

编辑:

添加开放时间的classDefinition
class OpeningTime extends Model {
    public static $_table     = 'openingtime';
    public static $_id_column = 'id';  
    public function getId(){
        return $this->id;
    }
    public function getDayOfWeek(){
        return $this->dayOfWeek;
    }
    public function getBegin(){
        return $this->begin;
    }
    public function getEnd(){
        return $this->end;
    }
    public function setBegin($begin){
        $this->begin = htmlentities( strip_tags($begin), ENT_QUOTES);
    }
    public function setEnd($end){
        $this->end = htmlentities( strip_tags($end), ENT_QUOTES);
    }
    public function setDayOfWeek($dayOfWeek){
        $this->dayOfWeek = htmlentities( strip_tags($dayOfWeek), ENT_QUOTES);
    }
}

问题是设定器,更确切地说是函数 htmlenties() and strip_tags()我在设定器中使用了。如果给定值为null,则这些函数返回一个空字符串。
我的解决方案现在:

public function setBegin($begin){
    if(isset($begin)){
        $this->begin = htmlentities( strip_tags($begin), ENT_QUOTES);
    }
    else{
        $this->begin = null;
    }
}

谢谢!

最新更新