How to check if a MySQL query using the legacy API was successful?

前端 未结 6 1953
栀梦
栀梦 2020-12-01 13:48

How do I check if a MySQL query is successful other than using die()

I\'m trying to achieve...

mysql_query($query);

if(success){
//move         


        
6条回答
  •  孤城傲影
    2020-12-01 14:24

    If your query failed, you'll receive a FALSE return value. Otherwise you'll receive a resource/TRUE.

    $result = mysql_query($query);
    
    if(!$result){
        /* check for error, die, etc */
    }
    

    Basically as long as it's not false, you're fine. Afterwards, you can continue your code.

    if(!$result)
    

    This part of the code actually runs your query.

提交回复
热议问题