Android via PHP connect Baidu Cloud Database _php Tutorial

Source: Internet
Author: User

Android Connect to Baidu Cloud database via PHP



To use PHP to the Baidu Cloud database operation, the first through the PHP file to connect to the Baidu Cloud, the connection cloud database PHP file name is conn, the content is as follows:

 
  

User login:

PHP file, where the user table is created in the Baidu Cloud database.

 
  

The Android program requires an incoming account number and password, and both the account and password are identical to those in PHP, both ID and pwd.
ArrayList
 
  
   
   list=new ArrayList
  
   
    
   () list.add (new Basicnamevaluepair ("id", et_ Accounts.gettext (). ToString ()); List.add (New Basicnamevaluepair ("pwd", Et_password.gettext (). ToString ())); String flag=cloudconnection.gotologin (Loginuri, list);
  
   
 
  

If the login succeeds then the value of flag is ' OK ', otherwise the flag is ' illegal user '.



Multiple queries, such as looking up all the tweets in a table from a cloud database, table fields:

Mbid: Weibo ID

MBUID: User ID to post this Weibo

Mbcontent: micro-Blog Content

Mbtime: Time to post Weibo

Mbnumzan: How many likes this Weibo

Mbnumping: Comments on the number of Weibo
Picname: The name of the published picture

Then the PHP file is:

 
  $Mbid, Mbuid = $Mbuid, mbcontent = $Mbcontent, Mbtime = $Mbtime, Mbnumzan = $Mbnumzan, mbnumping = $ mbnumping,nickname=> $nickname,iname=> $iName,picname=> $picName); Array_push ($user, $ary);} $users [' Microblog ']= $user; Echo Json_encode ($users);? >

Because PHP returns an array of objects, the data obtained from the cloud database in PHP is parsed and the parsed data exists in the list.

public class microblog_db {String senduri= "https://oursvn.duapp.com/query_microblog.php";//senduri the path to your PHP file public List
 
  > GetData () {List
  
   > List=new ArrayList
   
    > (); StringBuilder builder = new StringBuilder (); HttpPost HttpRequest = new HttpPost (Senduri); Try{httpresponse httpresponse=new defaulthttpclient (). Execute ( HttpRequest);//HTTP request issued,
    Get HTTP response
    
    If the status code is 200, the request succeeds, fetching the return data BufferedReader reader = new BufferedReader (New InputStreamReader (Httpresponse.getentity (). GetContent ())); for (String s = reader.readline (); s! = null; s = Reader.readline ()) {builder.append (s);} String jsonstring = builder.tostring (); jsonstring = jsonstring.substring (Jsonstring.indexof ("{"), Jsonstring.lastindexof ("}") +1); Jsonobject jsonobject = new Jsonobject (jsonstring); Jsonarray Jsonarray = Jsonobject.getjsonarray ("microblog");//microblog going to PHP
    $users [' Microblog ']= $user's microblog name matchesfor (int i=0;i
    
     Map = new HashMap
     
      
       (); Map.put ("Zan", R.drawable.zan); Map.put ("ping", r.drawable.ping); Map.put ("Head", R.drawable.tou12); Map.put ( "nickname", nickname), Map.put ("content", mbcontent), Map.put ("Sendtime", Mbtime), Map.put ("Zannum", Mbnumzan); Map.put ("Pingnum", mbnumping); Map.put ("Mbid", String.valueof (Mbid)); List.add (map);}} catch (Exception e) {e.printstacktrace ();} return list;}} 
      
     
    
   
  
 


If it is a query rather than multiple queries, then you can also use a number of query methods to implement, but for the loop only once loop.


http://www.bkjia.com/PHPjc/907368.html www.bkjia.com true http://www.bkjia.com/PHPjc/907368.html techarticle Android through the PHP connection Baidu Cloud database to use PHP to the Baidu Cloud database operation, all must first through the PHP file to connect to the Baidu Cloud, the connection cloud database PHP file name is conn, inside ...

  • 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.