$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.