Exemplo n.º 1
0
 public static function loadAll()
 {
     $dbWrapper = new DBWrapper();
     $connection = $dbWrapper->getConnection();
     $query = "SELECT * FROM topics";
     $topics = array();
     foreach ($connection->query($query) as $row) {
         $topic = new Topic($row['id'], $row['name'], $row['post_date'], $row['comment_count'], $connection);
         $topic->setComments();
         $topics[] = $topic;
     }
     return $topics;
 }
Exemplo n.º 2
0
 public function __construct($id = null, $topicID = null, $comment = null, $date = null, $author = null, $connection = null)
 {
     $this->id = $id;
     $this->topicID = $topicID;
     $this->comment = $comment;
     $this->date = $date;
     $this->author = $author;
     if (!isset($connection)) {
         $dbWrapper = new DBWrapper();
         $this->connection = $dbWrapper->getConnection();
     } else {
         $this->connection = $connection;
     }
 }
 public function __construct()
 {
     $dbWrapper = new DBWrapper();
     $this->connection = $dbWrapper->getConnection();
 }
Exemplo n.º 4
0
<?php

namespace ActiveRecord;

require_once 'Comment.php';
require_once '../DBWrapper.php';
use DBWrapper\DBWrapper;
$dbWrapper = new DBWrapper();
$connection = $dbWrapper->getConnection();
$topicIds = array();
foreach ($connection->query('SELECT id FROM topics') as $row) {
    $topicIds[] = $row['id'];
}
$bla = "blablablabla";
$comment = new Comment($connection);
$comment->setAuthor('Author' . rand(0, 1000));
$comment->setTopicID($topicIds[rand(0, sizeof($topicIds) - 1)]);
$comment->setComment(substr($bla, 0, rand(12, strlen($bla))));
$comment->save();
echo "<div>" . $comment->getTopicID() . "</div>";
echo "<div>" . $comment->getAuthor() . "</div>";
echo "<div>" . $comment->getComment() . "</div>";