qxzhan hat die Gist bearbeitet 2 months ago. Zu Änderung gehen
1 file changed, 25 insertions
php(Datei erstellt)
| @@ -0,0 +1,25 @@ | |||
| 1 | + | <?php | |
| 2 | + | require_once dirname(__FILE__) . '/../config.inc.php'; | |
| 3 | + | $db = \Typecho\Db::get(); | |
| 4 | + | try { | |
| 5 | + | $query = $db->select('title', 'url', 'logo') | |
| 6 | + | ->from('table.friends') | |
| 7 | + | ->where('status = ?', 1); | |
| 8 | + | $rows = $db->fetchAll($query); | |
| 9 | + | $friends = []; | |
| 10 | + | foreach ($rows as $row) { | |
| 11 | + | $friends[] = [ | |
| 12 | + | $row['title'], | |
| 13 | + | $row['url'], | |
| 14 | + | $row['logo'] ?? '' | |
| 15 | + | ]; | |
| 16 | + | } | |
| 17 | + | $output = [ | |
| 18 | + | 'friends' => $friends | |
| 19 | + | ]; | |
| 20 | + | header('Content-Type: application/json; charset=utf-8'); | |
| 21 | + | echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); | |
| 22 | + | } catch (\Typecho\Db\Exception $e) { | |
| 23 | + | header('Content-Type: application/json; charset=utf-8'); | |
| 24 | + | echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE); | |
| 25 | + | } | |
Neuer
Älter