我在我的 PHP 项目中使用 Idiorm 和 Paris。
我想在我的 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 插入了一个空字符串,而不是 null。
是否有可能添加 null 而不是空字符串?感谢您的帮助!
编辑:下面添加了OpeningTime的类定义
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);
}
}