我正在尝试插入新数据,当且仅当该数据在数据库中不存在时,如果它存在,只需中断插入操作并获取下一项并尝试再次检查并插入,我想要这样的东西:
insert into db if field_id doesnot exist, if exist, dont touch anything, neither update nor anything
ON DUPLICATE KEY UPDATE
不是我想要的,INSERT IGNORE
现在对我来说似乎很神秘
这是我的尝试:
$check = "SELECT anzeige_id FROM table WHERE anzeige_id = '$whatIhaveInMyHand'";
$checked=mysql_query($check);
if(mysql_num_rows($checked)==0){
$sql = "INSERT INTO table (`firmen_id`,`anzeige_id`,`anzeige_txt`) VALUES ('$firma_id','$anzeigen_id','$anzeige_txt')";
$sql_inserted = mysql_query($sql);
if($sql_inserted){
echo "inserted into db <br/>";
}else{
echo "anzeige_id already exists ".$anzeigen_id."<br/>";
}
什么对我的计划有好处?