且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何避免使用php在SQLite表中添加冗余数据?

更新时间:2023-12-01 13:29:16

您的选择没问题,但您需要将结果存储到一个变量中,例如:

Your selection is fine, but you need to store result into an variable like:

$count = $db->querySingle("SELECT COUNT(*) as count FROM Podcast_Export WHERE House_number = '".$value."'"); 
if($count <= 0){ 
    $db->exec("INSERT INTO Podcast_Export (House_number,Status) 
               VALUES ('".$value."', 'Go')");
}

使用 querySingle 获取 SQLite 中的行数.

Using querySingle to get the no of rows in SQLite.

请注意,我在此处将 House# 更改为 House_number 并删除了 AND status = 'GO' 子句,因为它们都具有GO 状态.

note that, i have chanaged the House# to House_number here and removed AND status = 'GO' clause as all of them having GO status.