Reputation: 155
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();
?>
Upvotes: 0
Views: 47
Reputation: 1339
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
Upvotes: 1