我每 5 分钟在一个正在提取 xml 提要的文件上运行一次 cronjob,目前它只是将该提要添加到数据库中,所以我可能会低于。
title, this is a new title
title, this is another title
但我遇到的问题是当 cron 再次运行时,我低于
title, this is a new title
title, this is another title
title, this is a new title
title, this is another title
当它再次运行时
title, this is a new title
title, this is another title
title, this is a new title
title, this is another title
title, this is a new title
title, this is another title
等等.....
我只希望它插入一条记录,如果它们不是已经在数据库中具有相同标题的记录,因此我的 cron 作业将继续运行,当它注意到不同的标题时,它会将其插入到数据库中。
我尝试了很多单独的选项,例如 not_like 等。
有人能告诉我最好的方法吗???
谢谢 ;)
我设法用以下方法做到了,但绝对不是最好的方法
function addResults($data){
$this->db->select('title');
$this->db->from('articles');
$this->db->where('title = ' . "'" . $data['title'] . "'");
//$this->db->limit(1);
$query=$this->db->get();
echo $query->num_rows();
if($query->num_rows()){
}else{
echo 'New Record ' . $data['title'];
$this->db->set('date', 'NOW()', FALSE);
$this->db->insert('articles', $data);
}
}