什么是跳过MySQL INSERT的正确方法

I have a foreach statement looping through JSON data and inserting the contents into MySQL. I want to skip the insert if a specific username is shown for $author string. Is the below method ok or is it better to handle at the database level?

foreach ($response['data'] as $data) {      
        $id = $data['id'];
        $created_time = $data['created_time'];
        $thumbnail = $data['images']['low_resolution']['url'];
        $author = $data['user']['username'];
        $caption = mysql_real_escape_string($data['caption']['text']);
        $link = $data['link'];
        $likes = $data['likes']['count'];

        if ($author == 'USERNAME') {
            mysql_close($con);
        } else {

        $query = "INSERT IGNORE INTO pbr (id, created_time, thumbnail, author, caption, link, likes, hash) VALUES ('$id', '$created_time', '$thumbnail', '$author', '$caption', '$link', '$likes', '$hash')";
        $result = mysql_query($query) or die(mysql_error());        

    mysql_close($con);
        }
    }

Why closing SQL connection at each loop iteration?

Why not simply do:

if ($author == 'USERNAME')
  continue; // next iteration

$query = "INSERT IGNORE INTO pbr (id, created_time, thumbnail, author, caption, link, likes, hash)
  VALUES ('$id', '$created_time', '$thumbnail', '$author', '$caption', '$link', '$likes', '$hash')";
$result = mysql_query($query) or die(mysql_error());

BTW you should bind parameters to your queries, or at least use mysql_real_escape_string() otherwise will have problems with values containing quotes (currently, you only do it for variable $caption, I guess that $link, $thumbnail and $username can contain single quotes as well).