예제 #1
0
 public static function find($column = '*', $value = NULL, array $options = array())
 {
     $query = 'SELECT * FROM log';
     $params = array();
     if ($column != '*' && strlen($column) > 0 && $value != NULL) {
         $query .= ' WHERE ' . Database::makeTableOrColumnName($column) . ' = :value';
         $params[':value'] = $value;
     }
     if (isset($options['orderby']) && isset($options['sort'])) {
         $query .= ' ORDER BY ' . Database::makeTableOrColumnName($options['orderby']) . ' ' . strtoupper($options['sort']);
     }
     if (isset($options['limit'])) {
         $query .= ' LIMIT ' . $options['limit'];
     }
     $sql = System::getDatabase()->prepare($query);
     $sql->execute($params);
     if ($sql->rowCount() == 0) {
         return NULL;
     } else {
         if ($sql->rowCount() == 1) {
             $row = $sql->fetch();
             $entry = new LogEntry();
             $entry->assign($row);
             return $entry;
         } else {
             $list = array();
             while ($row = $sql->fetch()) {
                 $entry = new LogEntry();
                 $entry->assign($row);
                 $list[] = $entry;
             }
             return $list;
         }
     }
 }