index.php
<?php
require_once __DIR__ . 'config.php';
class API {
function Select(){
$db = new Connect;
$users = array();
$data = $db->prepare('SELECT * FROM drivers ORDER BY id');
$data->execute();
while($OutputData = $data->fetch(PDO::FETCH_ASSOC)){
$users[$OutputData['id']] = array(
'id' => $OutputData['id'],
'name' => $OutputData['name'],
'station' => $OutputData['station'],
'distance' => $OutputData['distance'],
'score' => $OutputData['score'],
'profile' => $OutputData['profile'],
'comments' => $OutputData['comments'],
);
}
return json_encode($users);
}
}
$API = new API;
header('Content-Type: application/json');
echo API->Select();
?>
我想将json嵌套在while部分中
function Select() { /* rest of your code */ }
进入:
public function Select() { /* rest of your code */ }
此后,当您创建新的obj:
$API = new API();
记住选择是函数。
echo $API->Select();