Check if Record Exists
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I found this on php.net to check if file exists. I want to check if record exists first, then do update, otherwise do an insert. if(record exist) { update query} else { insert query} I know how to update or insert, but don't know how to check if a record exists first. How is it done? 回答1: If you know how to do a SQL SELECT , then do that: $result = mysql_query("SELECT * FROM table1 WHERE something"); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { // do something } else { // do something else } Better yet, don't do this in PHP, use