get_result() - > fetch_assoc()返回0,即使num_rows为2

I have a function that accesses the database to get a message based on the recipients UserID.

function GetUnreadMessages($recipientID, $db) {
  $sql  = 'SELECT
                senderID AND headline AND message
            FROM
                Message
            WHERE
                 recipientID = ? AND unread = 1
            LIMIT 100';
  $stmt = $db->prepare($sql);
  if ($stmt) {
    $stmt->bind_param('i', $recipientID);
    $stmt->execute();
    return $stmt->get_result();
  }
  else {
    http_redirect("", array(
    section => "info",
    message => "Internal error while recieving messages!"
    ));
  }
}

Then I call this. $messageCount is 2 like it should be because there are two messages for my testuser.

 $messages = GetUnreadMessages($userID, $db);
 $messageCount =  $messages->num_rows;  // 2

But when I call this $messages is always 0. Any idea why?

 $message = $messages->fetch_array(MYSQL_ASSOC);  // 0

This gives you the logical AND of the values as one result:

select senderID AND headline AND message

You want this:

select senderID, headline, message

You separate fields with , not AND.

SELECT senderID, headline, message