简体   繁体   中英

How to identify sql query is executed or not?

$sql='SELECT sender 
      FROM messages 
      WHERE message_id = :message_id';
$sender_result = $db->query($sql, array(':message_id'=>$message_id));
$sender = $sender_result->fetch();

I use this to execute above sql. How can I use $sender in the If .

Try using TRY-CATCH as:

try {
   $sql='SELECT sender 
      FROM messages 
      WHERE message_id = :message_id';
   $sender_result = $db->query($sql, array(':message_id'=>$message_id));
   $sender = $sender_result->fetch();

} catch(PDOException $ex) {
    // handle exception by using your own logic
    echo "An Error occured!"; //a custom error message
    your_logging_function($ex->getMessage());
}

This is the simplest way you could test

$query = $DB->query(".....");

if($query) // will return true if succefull else it will return false
{
// code here
}
if(isset($sender[0]))){
            return TRUE;
        }
        else {
            return FALSE;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM