您的位置:首页 > 编程语言 > PHP开发

php连接返回json数据

2015-12-28 11:30 633 查看
<?php

    $link=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);

    mysql_query("set names 'utf8'");

    mysql_query("set character set utf8");

    mysql_query("set character_set_result=utf8");

    if($link)

    {

        mysql_select_db(SAE_MYSQL_DB,$link);

    }else{

        die(mysql_error());

    }
?>

<?php

require "mysql_connect.php";

$n=0;

$result=mysql_query("select * from news");

while($row=mysql_fetch_array($result)){

    $arr[$n++]=array("title"=>$row['title'],

        "desc"=>$row['desc'],

        "time"=>$row['time'],

        "content_url"=>$row['content_url'],

        "pic_url"=>$row['pic_url']

        );

}

echo json_encode($arr);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息