开发者

How do I write an if statement that checks for duplicate database entries?

开发者 https://www.devze.com 2022-12-10 14:27 出处:网络
How do I write an if statement in PHP that checks a database for $varialbe and have it only pe开发者_运维问答rform the action if $varialbe is not already in the database?You can count number of items

How do I write an if statement in PHP that checks a database for $varialbe and have it only pe开发者_运维问答rform the action if $varialbe is not already in the database?


You can count number of items in database by SELECT count(*) FROM table WHERE field=? query, and then insert record if there is no such records.

You can also add UNIQUE index to the table column you want to have only unique values


if (! DBA::RowExists("select 1 from table where key = '$varialbe'"))
{
 ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消