flash后台数据连接(PHP篇)之php&flash收藏夹


 这里就不多说了,应该很容易就可以看懂了!这里没有用TextArea而改用了DataGrid! :-) 刚学会!

importmx.remoting.Service;
importmx.services.Log;
importmx.rpc.RelayResponder;
importmx.rpc.FaultEvent;
importmx.rpc.ResultEvent;
importmx.remoting.PendingCall;
importmx.remoting.debug.NetDebug;
importmx.controls.Alert;//加入Alert,以便弹出一个提示信息
//InitializeaLogger
mx.remoting.debug.NetDebug.initialize();//initializetheNCD
varmyLogger:Log=newLog(Log.DEBUG,"logger1");
//overridethedefaultloghandler
myLogger.onLog=function(message:String):Void{
trace("myLogger-->>>"+message);
}
//设定全局Service
_global.svc=newService( 
 "http://localhost/amfphp/gateway.php",
 myLogger,
 "favorite",
 null,
 null);
/**
*设定添加按钮的动作
*/
append_btn.onRelease=function(){
varpc:PendingCall=svc.append(webname_txt.text,url_txt.text);//呼叫php中的append方法
pc.responder=newRelayResponder(this,"append_Result","onError");
webname_txt.text=url_txt.text="";//清空文本框
}
append_Result=function(re:ResultEvent){ //添加按钮响应结果
varid=re.result;
if(id!="error"){
 mx.controls.Alert.show("保存:"+id+"->成功","DebugMessage",Alert.YES,_root,false,"prueba",Alert.OK);
 refresh_data();//刷新数据
}
else{
 mx.controls.Alert.show("技术原因未成保存","DebugMessage",Alert.YES,_root,false,"prueba",Alert.OK);
}
}
/***
*刷新按钮
*/
refresh_btn.onRelease=function(){
favorite_dg.removeAllColumns();
refresh_data();
}
/**
*刷新数据
*/
functionrefresh_data(){
varpc:PendingCall=svc.get_data();
pc.responder=newRelayResponder(this,"getData_Result","onError");
}
/***
*接收数据显示
*/
functiongetData_Result(re:ResultEvent){
varrs=re.result;
favorite_dg.columnNames=["id_PK","webname","url","timeline"];
favorite_dg.dataProvider=rs;
/*遍历方法
f=rs.length;//数库集大小
for(vari=0;i<f;i++){ 
 favorite_dg.addItem({id_PK:rs.getItemAt(i).id_PK,webname:rs.getItemAt(i).webname,url:rs.getItemAt(i).url,timeline:rs.getItemAt(i).timeline});
}
*/
}
/***
*出错:-(
*/
functiononError(rs:FaultEvent){
mx.remoting.debug.NetDebug.trace({level:"None",message:"Therewasaproblem:"+fault.fault.faultstring});
}
refresh_data(); //初始数据
stop();php的服务<?php
/***
*php&flash收藏夹之amfphp实现+MySql
*
*这里要实现的功能是,用flash来展示和通过php来读写文本来
*实现一个收藏夹的功能
*
*数据的储存结构
*id_PK,webname,url,timeline
*/
classfavorite
{
var$dbhost="localhost";//数据库地址
var$dbname="favorite";//数据库名称
var$dbuser="root"; //数据库用户名
var$dbpass=""; //数据库密码
var$conn;//数据库连
functionfavorite(){
 $this->methodTable=array(
 "get_data"=>array(
  "description"=>"Returnsdata",
  "access"=>"remote",
  "returntype"=>"recordSet"//返回数据为数据集(上例为字符串)
 ),
 "append"=>array(
  "description"=>"InsertsaData",
  "access"=>"remote",
  "arguments"=>array("name","url"),//需要两个参数
  "returntype"=>"String"
 ),
 );
 //连接数据库
 $this->conn=mysql_pconnect($this->dbhost,$this->dbuser,$this->dbpass);
 //$this->conn=mysql_pconnect($this->dbhost,$this->dbuser,$this->dbpass);
 mysql_select_db($this->dbname);
}
/**
*实现添加的功能
*@$name:收藏的网站名
*@$url:网址
*/
functionappend($name,$url){
 $rs=mysql_query("INSERTINTOtbl_favorite(webname,url)VALUES(’".$name."’,’".$url."’)");
 if(mysql_error())return"error";
 elsereturn$name;
}
/***
*实现读取功能
*返回:数组
*/
functionget_data(){
 returnmysql_query("SELECT*FROMtbl_favorite");
}
}
//debug
//$f=newfavorite;
//print_r($f->get_data());
//$f->append("korptonsblog","http://www.oiasoft.com");
?>少了一个mysql:--phpMyAdminSQLDump
--version2.8.2
--http://www.phpmyadmin.net
--
--主机:localhost
--生成日期:2007年04月08日13:04
--服务器版本:5.0.19
--PHP版本:5.0.4
--
--数据库:`favorite`
--
----------------------------------------------------------
--
--表的结构`tbl_favorite`
--
CREATETABLE`tbl_favorite`(
 `id_PK`int(11)unsignedNOTNULLauto_increment,
 `webname`varchar(20)NOTNULL,
 `url`varchar(100)NOTNULL,
 `timeline`timestampNOTNULLdefaultCURRENT_TIMESTAMPonupdateCURRENT_TIMESTAMP,
 PRIMARYKEY (`id_PK`)
)ENGINE=MyISAMDEFAULTCHARSET=utf8AUTO_INCREMENT=5;
--
--导出表中的数据`tbl_favorite`
--
INSERTINTO`tbl_favorite`(`id_PK`,`webname`,`url`,`timeline`)VALUES(1,’korptonsblog’,’http://www.oiasoft.com/’,’2007-04-0812:21:17’),
(2,’yahoo’,’http://cn.yahoo.com’,’2007-04-0812:12:33’),
(3,’kk’,’http://ww’,’2007-04-0812:45:33’),
(4,’kfc’,’http://www.kfc.com.cn’,’2007-04-0812:46:52’);

本文作者:
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3