How can I pour result db in array and send with json ?
<?php
$db = new PDO('mysql:host=localhost;dbname=Contact', 'root', '');
$stmt = $db->query('SELECT * FROM myfeilds');
$results = $stmt->fetchAll();
?>
How can I pour result db in array and send with json ?
<?php
$db = new PDO('mysql:host=localhost;dbname=Contact', 'root', '');
$stmt = $db->query('SELECT * FROM myfeilds');
$results = $stmt->fetchAll();
?>
收起
you can use json_encode
function to converting into json.
<?php
$db = new PDO('mysql:host=localhost;dbname=Contact', 'root', '');
$stmt = $db->query('SELECT * FROM myfeilds');
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); /* it will give you array of result */
$jsonResult = json_encode($results) ; /* it will convert into json format */
echo $jsonResult ; /* this will show in ajax success calling */
?>
for more json_encode
you can read manual json_encode
报告相同问题?