Interaction between iOS Development and PHP background development

Source: Internet
Author: User

<?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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.