Best way to check if MySQL results returned in PHP?

前端 未结 11 1058
长情又很酷
长情又很酷 2020-11-28 23:21

I\'m looking for the best way to check and see if any results were returned in a query. I feel like I write this part of code a lot and sometimes I get errors, and sometimes

11条回答
  •  死守一世寂寞
    2020-11-29 00:06

    Of all the options above I would use

    if (mysql_num_rows($result)==0) { PERFORM ACTION }

    checking against the result like below

    if (!$result) { PERFORM ACTION }
    

    This will be true if a mysql_error occurs so effectively if an error occurred you could then enter a duplicate user-name...

提交回复
热议问题