function __construct() { parent::__construct(); $this->extra_statement = "ORDER BY date DESC"; }
public function selectCollection(Collection $collection) { $fields = implode(",", $collection::getFieldsNames()); $table = $collection::getTableName(); $condition = $collection->getWhereStatement(); $extra = $collection->getExtraStatement(); if (empty($condition)) { $query = "SELECT {$fields} FROM {$table} {$extra}"; } else { $query = "SELECT {$fields} FROM {$table} WHERE {$condition} {$extra}"; } $stmt = $this->mysqli->prepare($query); if (!$stmt) { throw new ApplicationException("cannot prepare statement"); } $stmt->execute(); $result = $stmt->get_result(); if ($result) { $classname = $collection::getClassName(); while ($row = $result->fetch_assoc()) { $collection->add(new $classname($row)); } return true; } return false; }