获取项目更新的mysql结果

时间:2012-05-31 23:24:51

标签: php mysql

我如何改变我的PHP代码,所以它可以回应“如果该项目刚刚被创建或更新?”

$query_item_create = "INSERT INTO `item` (`category_id`, `id`) VALUES ('$catid', '$id')";
$query_item_update = "UPDATE `item` SET `date`='$date',`info`='$info' WHERE `id`='$id'";
mysql_query($query_item_create);
mysql_query($query_item_update);

1 个答案:

答案 0 :(得分:2)

以下更好地解释:http://php.net/manual/en/function.mysql-affected-rows.php

$affected = mysql_affected_rows();
if($affected > 0)
   echo "row was updated/inserted";
else
   echo "No rows were ....";