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