prepare('SELECT *, UNIX_TIMESTAMP(`key_created`) AS `key_created` FROM `fm_public_keys` WHERE `key_deprecated` IS NULL AND `key_level` >= :level ORDER BY `key_level` DESC, `key_id`'); $keys->bindValue('level', $minLevel); $keys->execute(); $keys = $keys->fetchAll(PDO::FETCH_OBJ); if($json) { $items = []; foreach($keys as $key) { $items[] = $item = new stdClass; $item->algo = $key->key_algo; $item->key = $key->key_body; if($includeComment) { $item->comment = $key->key_comment; $item->created = date(DateTime::ATOM, $key->key_created); $item->level = $key->key_level; } } echo json_encode($items); } else { foreach($keys as $key) { printf('ssh-%s %s', $key->key_algo, $key->key_body); if($includeComment) printf(' %s (%s)', $key->key_comment, date('M Y', $key->key_created)); echo "\n"; } }