Query interaction between PHP and the Java Android client

Source: Internet
Author: User
Tags php server

PHP Server side:

    function GetIDs () {$this->output->set_header (' Content-type:application/json; Charset=utf-8 ');        $jsonstr = ";        $pname = $pcallid = $pworkid = ";        if (isset ($_get[' name ')) {$pname = $_get[' name '];        } if (Isset ($_get[' callid ')) {$pcallid = $_get[' callid '];        } if (Isset ($_get[' WorkID ')) {$pworkid = $_get[' WorkID '];        } $this->load->model (' Wireid_model ');        $this->wireid_model->insertonly ($pname, $pcallid);        if ($pname = = ' && $pcallid = = ' && $pworkid = = ') {die ();            } else {$sqlstr = ' select * from Twireid where 1=1 '; if ($pname! = ") {$sqlstr = $sqlstr.            "and Gname= ' {$pname} '"; } else if ($pcallid! = ") {$sqlstr = $sqlstr.                "and Goldcallid= ' {$pcallid} '";       } else if ($pworkid! = ") {                 $sqlstr = $sqlstr.                    "and Gcardid= ' {$pworkid} '";            } $getdata = $this->wireid_model->getsql ($SQLSTR);            Json_force_object prevent the appearance of [] $jsonstr = Json_encode ($getdata->result_array (), json_force_object);        Echo $jsonstr; }    }

Java android:

Doasktask = new Runnable () {@Overridepublic void Run () {///todo//HTTP request is made here. Network requests related Operations Ggname = Etname.gettext (). ToS Tring (); ggworkid = Etworkid.gettext (). ToString (); ggcallid = Etcallid.gettext (). ToString (); String BaseURL = Confiddatas.askbaseurl; String askstr = "Name=" + ggname + "&callid=" + ggcallid+ "&workid=" + ggworkid; String result = null; HttpGet httpget = new HttpGet (BaseURL + askstr);//The second step is to use the Execute method to send an HTTP GET request and return the HttpResponse object HttpResponse HttpResponse = null;try {HttpResponse = new defaulthttpclient (). Execute (httpget);} catch (Clientprotocolexception e) {// TODO auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Message msg = new Message (); Bundle data = new Bundle (), if (Httpresponse.getstatusline (). Getstatuscode () = = 200) {//Third step, use the GetEntity method to live to return the result try { result = Entityutils.tostring (Httpresponse.getentity ());d ata.putstring ("value", result);d ata.putstring ("Result", " isOK "); Msg.setdata (dATA); handler.sendmessage (msg);} catch (ParseException e) {//E.printstacktrace ();} catch (IOException e) {//E.printstacktrace ();}} else {//Error data.putstring ("Value", "");d ata.putstring ("result", "iserr"); Msg.setdata (data); Handler.sendmessage (msg );}}};

  

Query interaction between PHP and the Java Android client

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.