示例#1
0
 /**
  * Will return one of the following:
  *
  *  2-D array of all comments from all users contained the 'Comments' table
  *  OR
  *  A string advising there are no comments in the 'Comments' table
  *
  * @return array|string
  */
 public static function getComments()
 {
     // Get DB Connection
     self::$DB = DBConnection::getConnection();
     // Query for Read-Only. Order by comment date posted
     $result = self::$DB->query("SELECT Comments.comm_Title, Comments.comm_Body, Comments.comm_Date_Posted, Users.user_Username FROM Comments INNER JOIN Users ON Comments.user_ID = Users.user_ID ORDER BY comm_Date_Posted DESC");
     // Array to return to view
     if ($result->rowCount() === 0) {
         $comments = "No comments at this time";
     } else {
         $comments = [];
         // Store the comments to return to the web view
         while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
             // Title, Message, Logged-In Username and Date-Time stamp
             $comments[] = $row;
         }
     }
     // Nullify the DB object
     $DB = null;
     return $comments;
 }