输出JSON

<?php
header("Content-type: text/html; charset=utf-8"); 
$host = '数据库IP';
$dbname = '数据库名称';
$user = '用户名';
$pw = '密码';
$pdo = new PDO("mysql:host=".$host.";dbname=".$dbname."",$user,$pw); //通过PDO连接数据库
$sql = 'SELECT * FROM `新闻表` WHERE 1 ';
$arr = $pdo->query($sql)->fetchall();
echo json_decode($arr); //输出JSON
?>

猜你喜欢

转载自www.cnblogs.com/xiongwei/p/10714952.html
今日推荐