Is it possible to insert a row but only if a value does not already exist?

前端 未结 7 1855
谎友^
谎友^ 2021-02-04 05:26

Is it possible to insert a row, but only if one of the values already in the table does not exist?

I\'m creating a Tell A Friend with referral points for an eco

7条回答
  •  无人共我
    2021-02-04 05:47

    I'm not sure if I got it, but what about a

    try {
      mysql_query($sql);
    }
    catch(Exception $e) {
    
    }
    

    combined with an unique field index in MySQL?

    if it throws an exception then you know that you got a duplicated field. Sorry if that don't answer your question..

提交回复
热议问题