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

后端 未结 8 1333
佛祖请我去吃肉
佛祖请我去吃肉 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:40

    well...

    by definiton mysql_query:

    mysql_query() returns a resource on success, or FALSE on error.

    but what you need to understand is if this function returns a value different than FALSE the query has been ran without problems (correct syntax, connect still alive,etc.) but this doesnt mean you query is returning some row.

    for example

     true
    
    ?>
    

    so if you get FALSE you can use

    mysql_errorno() and mysql_error() to know what happened..

    following with this:

    you can use mysql_fetch_array() to get row by row from a query

提交回复
热议问题