need to test if sql query was successful

后端 未结 11 1285
遥遥无期
遥遥无期 2021-02-18 17:54

I have this query and if it returns successful, I want another function to process, if not, do not process that function.

Here is the code for running the query

相关标签:
11条回答
  • 2021-02-18 18:29

    Check this:

    <?php
    if (mysqli_num_rows(mysqli_query($con, sqlselectquery)) > 0)
    {
        echo "found";
    }
    else
    {
        echo "not found";
    }
    ?>
    
    <!----comment ---for select query to know row matching the condition are fetched or not--->
    
    0 讨论(0)
  • 2021-02-18 18:32
    if ($DB->rowCount() > 0)
       {/* Update worked because query affected X amount of rows. */}
    else
        {$error = $DB->errorInfo();}
    
    0 讨论(0)
  • 2021-02-18 18:33

    mysql_affected_rows

    I understand that by saying "successful" you want to know if any rows have been updated. You can check it with this function.

    If you use PDO -> http://www.php.net/manual/en/pdostatement.rowcount.php

    0 讨论(0)
  • 2021-02-18 18:38

    mysqli_affected_rows returns number of items affected.

    0 讨论(0)
  • 2021-02-18 18:39

    You can use this to check if there are any results ($result) from a query:

    if (mysqli_num_rows($result) != 0)
     {
      //results found
     } else {
      // results not found
     }
    
    0 讨论(0)
提交回复
热议问题