天天看点

Flash(AS2.0)与php通讯 分享

不好意思,贴上瘾了,没想到flash+php+mysql这么顺利就搞定了,自己赏跟白沙,哈哈Flash代码://第一桢var sendLoad:LoadVars = new LoadVars();var acceptLoad:LoadVars = new LoadVars();sendLoad.userName = "Billows";sendLoad.sendAndLoad("../php/conn_db.php", acceptLoad, "POST");//sendLoad.sendAndLoad("http://localhost/Flash&PHP/php/conn_db.php", acceptLoad, "POST");acceptLoad.onLoad = function(success) { if (success) { var myText = _root.createTextField("Billows", 0, 100, 100, 100, 100); myText.html = true; myText.htmlText = this.data; }};flash里和上面的差不多,这里用比较方便的LoadVars类来实现PHP代码:<?php$ userName = $ _POST['userName'];//Flash里传过来的值$ queryStr="SELECT * FROM username where name='".$ userName."'";//根据此变量查询mysql里数据mysql_connect("localhost","root","");//localhost本地数据库//root用户名//""密码mysql_select_db("test");//选择mysql里数据库$ qr = mysql_query($ queryStr);//执行查询$ nrows = mysql_num_rows($ qr); //取到符合查询条件的表里总的记录数for ($ i=0; $ i < $ nrows; $ i++){$ row = mysql_fetch_array($ qr); //取出数组$ data = $ row['password'].", ".$ row['name']."

"; //取出记录echo "&data=".urlencode($ data)."&";//输出到Flash}?>至于数据库我也接触的少,如果sql用的不熟的话,Mysql数据库,表,字段的建立可以用MySql-front来借助实现,很方便的。好了,php研究至此,以后要用的时候在研究吧。