php
· 821 B · PHP
原始文件
<?php
require_once dirname(__FILE__) . '/../config.inc.php';
$db = \Typecho\Db::get();
try {
$query = $db->select('title', 'url', 'logo')
->from('table.friends')
->where('status = ?', 1);
$rows = $db->fetchAll($query);
$friends = [];
foreach ($rows as $row) {
$friends[] = [
$row['title'],
$row['url'],
$row['logo'] ?? ''
];
}
$output = [
'friends' => $friends
];
header('Content-Type: application/json; charset=utf-8');
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} catch (\Typecho\Db\Exception $e) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
}
| 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 | } |