<?php
$pdo = new PDO("mysql:dbname=sample;host=localhost", "admin", "passwd");
$statement = $pdo->prepare("SELECT first_name, last_name FROM accounts WHERE account_id='1'");
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
echo "$json";
?>
结果是
[{"first_name":"John","last_name":"Doe"}]
使用 javascript 的预期结果:
John Doe
陪伴而非守候