检查列,如果为空,则执行更新


check column if empty then do update

家伙我有一个大的数据库,所以当我想完全更新我的一些列我有超时错误(我尝试一些方法来增加超时和失败),但我的问题是我想绕过这个问题,我想更新我的空列在一些表。所以我想使用这个查询代码,但我有空白页没有错误,有人能告诉我有什么问题,或者如果可能的话,请告诉我一个好方法。

    $sql = 'SELECT topic_first_poster_avatar FROM ' . TOPICS_TABLE . ' WHERE topic_poster = ' . (int) $row['user_id'] . 'IF topic_first_poster_avatar = "" 
        SET topic_first_poster_avatar =  ''' . $db->sql_escape($avatar_info);
    $db->sql_query($sql);

正如plalx在评论中所说,您不需要SELECT或IF,您可以为更新语句指定WHERE,并使用and/or具有多个约束。

$sql = "UPDATE ". TOPICS_TABLE ." 
       SET topic_first_poster_avatar =  '" . $db->sql_escape($avatar_info) ."'
       WHERE topic_poster = " . (int) $row['user_id'] . " AND topic_first_poster_avatar = ''";