**********************************************************************************************/*This is a small interface created by PHP*/<?PHP$mysqli=NewMysqli (' localhost ', ' root ', ' 123456 ', ' interfacetest '));Mysqli_query($mysqli, "Set names UTF8");if($mysqli-connect_error) { die(' Connect Error ('.$mysqli->connect_errno. ‘) ‘ .$mysqli-connect_error);}$output=Array();$user _by=$_post[' User_by '];$uid=$_post["UID"];if(Empty($user _by)) { $output=Array(' Data ' =NULL, ' info ' = ' This is null! ', ' Stats ' =>1); Exit(Json_encode ($output));}if($user _by= = ' Get_userinfo ') {//call the interface to get user information//query database $sql= "SELECT *" From user WHERE user_id=$uid"; $result=$mysqli->query ($sql); $userInfo=$result-Fetch_row (); if($userInfo){//If the data has output data $output=Array( ' Data ' =Array( ' UserInfo ' =$userInfo, ), ' Stats ' =>0 ); }Else{ $output=Array( ' Data ' =Array( ' UserInfo ' =$userInfo, ), ' Stats ' =>1 ); } Exit(Json_encode ($output));//feedback The results to the client} $mysqli-close ();? >**********************************************************************************/*This is a method of an interface call (POST)*/$url= ' http://localhost/testmysql.php ';$SL _data=Array( ' UID ' =>1, ' user_by ' = ' get_userinfo ');$ch=curl_init (); curl_setopt ($ch, Curlopt_url,$url);//the address to be accessedcurl_setopt ($ch, Curlopt_returntransfer, 0);//whether the execution result is returned, 0 is returned, 1 is not returned as 1 for transmitting data, and 0 for direct output displaycurl_setopt ($ch, Curlopt_post, 1);//send a regular POST requestcurl_setopt ($ch, Curlopt_postfields,Http_build_query($SL _data));$output= Curl_exec ($ch);//execute and get dataEcho $output; Curl_close ($ch);
?>
A short example of PHP creating interfaces and calling interfaces (local)