<?PHP/* How to create a PHP file 1): Locate the XAMPP and then create a new folder under the Htdocs file. Use your computer's text editor to save a new file to the desktop and then display the introduction to change the suffix name to. PHP last this file into the first created good folder and then you can write PHP code in it 2): iOS and PHP Communication protocol design and interactive iOS send network requests: Asynchronous and synchronous GET POST//This part is OC code part put here handy view/* GET Note: The first half of the URL is: Server address/php folder name/php file name of the second half: All field fields and fields with the & symbolic link to create two input boxes declared as attributes and then the text of the two input boxes are stored in Database created in nsurlsession *session = [Nsurlsession sharedsession]; Nsurl *url = [Nsurl urlwithstring:[nsstring stringwithformat:@ "http://127.0.0.1/phptest/avitest.php?name=%@& password=%@ ", _nametf.text,_passwordtf.text]]; Nsurlsessiontask *task = [Session Datataskwithurl:url completionhandler:^ (NSData * _nullable data, Nsurlresponse * _Nulla BLE response, Nserror * _nullable error) {nsstring *result = [[NSString alloc] Initwithdata:data Encoding:nsutf8strin Gencoding]; Nsdictionary *dic = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers | NsjsonreadingmutaBleleaves Error:nil]; NSLog (@ "result =%@", result); }]; [Task resume];*/ /* Nsurl *url = [Nsurl urlwithstring:@" http://127.0.0.1/phpTest/sssss.php "]; Nsmutableurlrequest *request = [Nsmutableurlrequest Requestwithurl:url]; Request. HttpMethod = @ "POST"; Request. Httpbody = [[NSString stringwithformat:@ "name=%@&password=%@", _nametf.text,_passwordtf.text] dataUsingEncoding : Nsutf8stringencoding]; Nsurlsession *session = [Nsurlsession sharedsession]; Nsurlsessiontask *task = [Session Datataskwithurl:url completionhandler:^ (NSData * _nullable data, Nsurlresponse * _Nulla BLE response, Nserror * _nullable error) {nsstring *result = [[NSString alloc] Initwithdata:data Encoding:nsutf8 Stringencoding]; NSLog (@ "%@", result); Nsdictionary *dic = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil]; NSLog (@ "result:%@", dic[@ "result"]); }]; [Task resume]; */ //This is the PHP code section//request request can either perform a POST or perform a GET request//$data = $_get; $data = $_post; $data=$_request; $name=$data["Name"]; $password=$data["Password"]; $array=Array(); //log in to the server database the first parameter: Database server address, second parameter: Server user name; third parameter: password $connect=mysql_connect("127.0.0.1", "Root", "" "); if($connect){ //echo (' Connection server succeeded '); $array["connecty"] = "Success"; }Else{ Echo("Connection Failed"); die; $array["Connect"] = "Error"; } //Select Database mysql_select_db("Person",$connect); //inserting a user name, password into the database if(mysql_query("INSERT into register (name, password) VALUES ('$name‘,‘$password‘)")){ //Echo ("Insert succeeded"); $array["result"] = "Success"; }Else{ //Echo ("Insert Failed"); $array["result"] = "Error"; } Echo(Json_encode ($array)); ?>
Interaction between iOS Development and PHP background development