女人帮第一季,王义廷,中央三套节目表
要用php对百度云进行操作的话,都要先通过php文件连接到百度云,连接云数据库的php文件名是conn,内容如下:
mysql库名 $cn = mysql_connect($dbhost,$dbuser,$dbpass) or die("connect error"); @mysql_select_db($dbname)or die("db error"); mysql_query("set names 'utf8'"); mysql_query("set character_set_client=utf8"); mysql_query("set character_set_results=utf8"); ?>
用户登录:
php文件,其中user表是在百度云数据库中创建的。
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);
如果登录成功那么flag的值为‘ok’,否则flag为'illegal user'。
多条查询,例如从云数据库中查找表中所有的微博,表的字段为:
mbid:微博id
mbuid:发表此微博的用户id
mbcontent:微博内容
mbtime:发表微博的时间
mbnumzan:赞此微博的数目
mbnumping:评论此微博的数目
picname:发表的图片的名字
那么php文件就是:
$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); ?>
因为php返回的是一个对象数组,所以要对php中从云数据库获得的数据进行解析,解析之后的数据存在list中。
public class microblog_db { string senduri="https://oursvn.duapp.com/query_microblog.php";//senduri为你php文件的路径 public list> getdata() { list> list=new arraylist>(); stringbuilder builder = new stringbuilder(); httppost httprequest = new httppost(senduri); try{ httpresponse httpresponse=new defaulthttpclient().execute(httprequest);//发出http请求,取得http response //若状态码为200则请求成功,取到返回数据 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要去php中$users['microblog']=$user的microblog名称一致 for(int i=0;imap = 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; } }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
YII2框架中使用RBAC对模块,控制器,方法的权限控制及规则的使用示例
YII2框架中ActiveDataProvider与GridView的配合使用操作示例
PhpStorm的使用教程(本地运行PHP+远程开发+快捷键)
网友评论