class getPosts
{
public $post_id;
public $title;
public $content;
public $author;
function __construct($inPost_id=null, $inTitle=null, $inContent=null, $inAuthor=null)
{
$this->post_id = $inPost_id;
$this->title = $inTitle;
$this->content = $inContent;
$this->author = $inAuthor;
}
function getPosts()
{
$postnumber = 14;
$query = $dbh->prepare("SELECT * FROM posts ORDER BY ID DESC LIMIT $postnumber");
$query->execute();
$postArray = array();
while ($row = $query->fetch())
{
$myPost = new getPosts($row["id"],
$row['title'], $row['content'],
$row['author'], $row["author_id"]);
array_push($postArray, $myPost);
}
return $postArray;
}
}
Это работает, но не так хорошо, так как вместо 14 он возвращает 15.
Хорошо ли использовать PDO::FETCH_ASSOC
в fetch()
?