省市区接口撰写文档

Original 2019-03-03 19:31:42 277
abstract:function getArea($pid){ $conn = mysqli_connect('127.0.0.1','root','root','php',3306); if(!$conn){ echo '数据库错误',mysqli_connect_error();
function getArea($pid){
	$conn = mysqli_connect('127.0.0.1','root','root','php',3306);

	if(!$conn){
		echo '数据库错误',mysqli_connect_error();
	}

	$sql = "select area_id,area_pid,area_name from php_area where area_pid={$pid}";

	$res = mysqli_query($conn,$sql);

	$data = [];
	while($row=mysqli_fetch_assoc($res)){
		$data[] = $row;
	}
	mysqli_close($conn);
	return json_encode($data);
}
标题:省市区接口文档
地址:http://localhost/test/a.php
传参:int $pid 
返回值:该id下所有下级地区
代码:
function getArea($pid){
$conn = mysqli_connect('127.0.0.1','root','root','php',3306);
 
if(!$conn){
echo '数据库错误',mysqli_connect_error();
}
 
$sql = "select area_id,area_pid,area_name from php_area where area_pid={$pid}";
 
$res = mysqli_query($conn,$sql);
 
$data = [];
while($row=mysqli_fetch_assoc($res)){
$data[] = $row;
}
mysqli_close($conn);
return json_encode($data);
}
返回值示例:
[
    {
        "area_id": "3",
        "area_pid": "2",
        "area_name": "东城区"
    },
    {
        "area_id": "4",
        "area_pid": "2",
        "area_name": "西城区"
    },
    {
        "area_id": "5",
        "area_pid": "2",
        "area_name": "崇文区"
    },
    {
        "area_id": "6",
        "area_pid": "2",
        "area_name": "宣武区"
}
]

QQ图片20181114103819.png

Correcting teacher:查无此人Correction time:2019-03-04 09:07:10
Teacher's summary:完成的不错。接口文档,一般不写代码,前端人员也看不懂,以免别人发现代码中有漏洞,进行攻击。

Release Notes

Popular Entries