输出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
?>

 

posted @ 2019-04-16 09:35  飞雪飘鸿  阅读(121)  评论(0编辑  收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL