title: PHP not displaying data from database
body: <p>I am trying to display a list of comments from a MySql database in PHP.</p>
  
  <p>The foreach loop works as it displays the necessary html for each comment in the database, but no actual content from the database is being pulled through.</p>
  
  <p>Comment class</p>
  
  <pre><code>class Comment {
  protected $_id;
  protected $_user;
  protected $_commentText;
  protected $_dateTimePosted;
  
  public function __construct()
  {
      $this-&gt;_dateTimePosted = new DateTime();
      $this-&gt;_dateTimePosted-&gt;format(DATE_RFC3339);
  }
  
  public function get_id()
  {
      return $this-&gt;_id;
  }
  public function set_id($value)
  {
      $this-&gt;_id = $value;
  }
  public function get_user()
  {
      return $this-&gt;_user;
  }
  public function set_user($value)
  {
      $this-&gt;_user = $value;
  }
  public function get_commentText()
  {
      return $this-&gt;_commentText;
  }
  public function set_commentText($value)
  {
      $this-&gt;_commentText = $value;
  }
  public function get_dateTimePosted()
  {
      return $this-&gt;_dateTimePosted;
  }
  public function set_dateTimePosted($value)
  {
      $this-&gt;_dateTimePosted = $value;
  }
  }
  </code></pre>
  
  <p>CommentFunctions.php</p>
  
  <pre><code>include 'dbConnect.php';
  
  class CommentFunctions {
  
  protected $conn;
  
  public function __construct()
  {
      $this-&gt;conn = dbConnect();
  }
  public function get_comments()
  {
      $sql = "SELECT * FROM comments";
  
      $stmt = $this-&gt;conn-&gt;stmt_init();
  
      $stmt-&gt;prepare($sql);
  
      $stmt-&gt;execute();
  
      $stmt-&gt;store_result();
  
      $comments = array();
  
      while ($row = $stmt-&gt;fetch())
      {
          $comment = new Comment();
  
          $comment-&gt;set_id($row['id']);
          $comment-&gt;set_user($row['user']);
          $comment-&gt;set_commentText($row['comment_text']);
          $comment-&gt;set_dateTimePosted($row['datetime_posted']);
  
          $comments[] = $comment;
      }
  
      return $comments;
  }
  }
  </code></pre>
  
  <p>Index.php</p>
  
  <pre><code>&lt;?php
  include './includes/Comment.php';
  include './includes/CommentFunctions.php';
  
  $comments_func = new CommentFunctions();
  
  $all_comments = $comments_func-&gt;get_comments();
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Comments&lt;/title&gt;
          &lt;link rel="stylesheet" type="text/css" href="./css/Master.css" /&gt;
          &lt;link rel="stylesheet" type="text/css" href="./css/Site.css" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="Container"&gt;
          &lt;h2&gt;Comments&lt;/h2&gt;
          &lt;a class="reload-comments" href="/"&gt;Refresh&lt;/a&gt;
          &lt;div id="Comments"&gt;
              &lt;?php if (!$all_comments) {
                  echo 'No comments yet.';
              } ?&gt;
              &lt;?php foreach ($all_comments as $c) { ?&gt;
              &lt;div class="comment"&gt;
                  &lt;input class="id" type="hidden" value="&lt;?php echo $c-&gt;get_id(); ?&gt;" /&gt;
                  &lt;div class="author"&gt;Posted by &lt;?php echo $c-&gt;get_user(); ?&gt;&lt;/div&gt;
                  &lt;div class="comment-text"&gt;
                      Posted &lt;?php echo $c-&gt;get_dateTimePosted(); ?&gt;
                      &lt;p&gt;&lt;?php echo $c-&gt;get_commentText(); ?&gt;&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;?php } ?&gt;
          &lt;/div&gt;
          &lt;div id="AddComment"&gt;
              &lt;form name="add_comment_form" id="add_comment_form" action="index.php" method="post"&gt;
                  &lt;label for="user"&gt;Your Name:&lt;/label&gt;
                  &lt;input name="user" id="user" type="text" /&gt;&lt;br /&gt;
                  &lt;label for="comment_text"&gt;Comment:&lt;/label&gt;
                  &lt;textarea name="comment_text" id="comment_text" rows="5" cols="10"&gt;&lt;/textarea&gt;&lt;br /&gt;
                  &lt;input name="submit" id="submit" type="submit" value="Submit" /&gt;
                  &lt;input id="reset" type="reset" class="hidden" /&gt;
              &lt;/form&gt;
          &lt;/div&gt;
          &lt;div class="loader"&gt;&lt;/div&gt;
          &lt;div class="response"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Comments can be added, the data is stored fine in the database, and the loop runs the correct number of times, but the code such as echo $c->get_commentText(); is not displaying a value.</p>
  
  <p>Appreciate any help.</p>