***.首先在MySQL数据库中创建如下的数据库(数据库名称:db_mxd) 以及表(表名称:userInfo)
1_1.删除数据的接口,接受客户端GET提交的userAccount,删除数据库中表userInfo中对应的用户的记录:
<?php $arr = array( 'code'=>'400', 'message'=>'Delete has Error', 'result'=>false ); if(isset($_GET['userAccount'])) { $userAccount = $_GET['userAccount']; $conn = mysql_connect('127.0.0.1', 'root', 'root') or die('Error Info : '.mysql_error()); mysql_select_db('db_mxd', $conn); $result = mysql_query("delete from userInfo where userAccount='$userAccount'", $conn); if($result) { $arr['code'] = '200'; $arr['message'] = 'Deleted Success'; $arr['result'] = $result; }1_2.接口测试mysql_free_result($result); // 关闭结果集 mysql_close($conn); //关闭MySQL服务器}else{
$arr['message'] = 'lack of Parmater';
}
echo json_encode($arr);
?>
在浏览器中使用如下链接进行测试:
http://localhost:63342/htdocs/m/mysql_delete.php?userAccount=123456
测试结果:
{"code":"200","message":"Deleted Success","result":true}
2_1.修改数据的接口,接受客户端以GET提交的userAccount参数,修改resume字段的内容:
<?php $arr = array( 'code' => '400', 'message' => 'update Error', 'result' => false ); if(isset($_GET['userAccount']) && isset($_GET['resume'])) { $userAccount = $_GET['userAccount']; $resume = $_GET['resume']; $conn = mysql_connect('127.0.0.1', 'root', 'root') or die('Error Info : '.mysql_error()); mysql_select_db('db_mxd', $conn); $result = mysql_query("update userInfo set resume='$resume' where userAccount='$userAccount'", $conn); if($result) { $arr['code'] = '200'; $arr['message'] = 'Update Success'; } $arr['result'] = $result;2_2.接口测试mysql_free_result($result); // 关闭结果集 mysql_close($conn); //关闭MySQL服务器
}else{
$arr['message'] = 'lack Parmetar';
}
echo json_encode($arr);
?>
使用下面的链接在浏览器中测试接口:
http://localhost:63342/htdocs/m/mysql_update.php?userAccount=1512547107&&resume="This is My Resume!"
测试结果:
{"code":"200","message":"Update Success","result":true}
数据库数据: