Whats the proper way to check if mysql_query() returned any results?

后端 未结 8 1332
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-05 17:03

I tried what seemed like the most intuitive approach

$query = \"SELECT * FROM members 
          WHERE username = \'$_CLEAN[username]\'
          AND password =          


        
8条回答
  •  名媛妹妹
    2021-02-05 17:46

    I used the following:

    if ($result != 0 && mysql_num_rows($result)) {

    If a query returns nothing it will be a boolean result and it's value will be 0.

    So you check if it's a zero or not, and if not, we know there's something in there..

    HOWEVER, sometimes it'll return a 1, even when there is nothing in there, so you THEN check if there are any rows and if there is a full row in there, you know for sure that a result has been returned.

提交回复
热议问题