标签:
调用前两篇的Db.php以及Controller.php
<?php require_once(‘./Db.php‘); require_once(‘./Controller.php‘); try { $connect=Db::getInstance()->connect(); } catch (Exception $e) { return Response::show(403,‘数据获取失败‘); } $sql=‘select * from tb_smartphone limit 5‘; $res=mysql_query($sql,$connect); $contents=array(); while ($content=mysql_fetch_assoc($res)) { $contents[]=$content; } if ($contents) { return Response::show(200,‘数据获取成功‘,$contents); }else{ return Response::show(400,‘数据获取失败‘,$contents); } ?>
结果,使用?format=json/xml选择输出数据格式,默认为json
标签:
原文地址:http://www.cnblogs.com/valentineisme/p/4200490.html