Since you're using MySQL, you can use on duplicate key update
clause:
Db::getInstance()->execute(
"INSERT INTO b2b_category (id_b2bcategory, name_b2bcategory, position_b2bcategory, active_b2bcategory)
VALUES (".$count.", '".$c1[9]."', '0', '0')
on duplicate key update name_b2bcategory = '".$c1[9]."'"
);
You can also use a select count(1)
instead of when exists
:
$cnt = Db::getInstance()->executeS("SELECT count(1) FROM b2b_category WHERE name_b2bcategory IN = '".$c1[9]."'");
if($cnt[0] == 0) {
Db::getInstance()->execute("INSERT INTO b2b_category (id_b2bcategory, name_b2bcategory, position_b2bcategory, active_b2bcategory) VALUES (".$count.", '".$c1[9]."', '0', '0')");
$count++;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…