mysql| Background | Data here is not much to say, it should be easy to see understand! There's no use of textarea to datagrid!. :-) Just learn! Import Mx.remoting.Service;
Import Mx.services.Log;
Import Mx.rpc.RelayResponder;
Import mx.rpc.FaultEvent;
Import mx.rpc.ResultEvent;
Import Mx.remoting.PendingCall;
Import Mx.remoting.debug.NetDebug;
Import Mx.controls.Alert; Join alert to pop up a message
Initialize a Logger
Mx.remoting.debug.NetDebug.initialize (); Initialize the NCD
var mylogger:log = new Log (log.debug, "logger1");
Override the default log handler
Mylogger.onlog = function (message:string): Void {
Trace ("mylogger-->>>" +message);
}
Set global Service
_global.svc = new Service (
"Http://localhost/amfphp/gateway.php",
MyLogger,
"Favorite",
Null
NULL);
/**
* Set the action to add a button
*/
Append_btn.onrelease = function () {
var pc:pendingcall = svc.append (Webname_txt.text,url_txt.text); The Append method in calling PHP
Pc.responder = new Relayresponder (This, "Append_result", "OnError");
Webname_txt.text = Url_txt.text = ""; Empty text box
}
Append_result = function (re:resultevent) {//Add button response result
var id = re.result;
if (ID!= "error") {
Mx.controls.Alert.show ("Save:" +id+ "-> Success", "Debug message", Alert.yes, _root, False, "Prueba", Alert.ok);
Refresh_data (); Refreshing data
}
else {
Mx.controls.Alert.show ("Technical reason not saved", "Debug message", Alert.yes, _root, False, "Prueba", Alert.ok);
}
}
/***
* Refresh button
*/
Refresh_btn.onrelease = function () {
Favorite_dg.removeallcolumns ();
Refresh_data ();
}
/**
* Refresh Data
*/
function Refresh_data () {
var pc:pendingcall = Svc.get_data ();
Pc.responder = new Relayresponder (This, "Getdata_result", "OnError");
}
/***
* Receive data display
*/
function Getdata_result (re:resultevent) {
var rs = Re.result;
Favorite_dg.columnnames = ["Id_pk", "WebName", "url", "timeline"];
Favorite_dg.dataprovider = RS;
/* Traversal method
f = rs.length; Number of library sets size
for (var i=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});
}
*/
}
/***
* ERROR:-(
*/
function OnError (rs:faultevent) {
Mx.remoting.debug.NetDebug.trace ({level: ' None ', message: "There is a problem:" + fault.fault.faultstring});
}
Refresh_data (); Initial data
Stop ();
the services of PHP<?php
/***
* amfphp implementation of PHP & Flash Favorites +mysql
*
* The function to be implemented here is to use Flash to display and read text from PHP to
* To achieve a favorite folder function
*
* Storage structure of data
* Id_pk,webname,url,timeline
*/
Class Favorite
{
var $dbhost = "localhost"; Database address
var $dbname = "Favorite"; Database name
var $dbuser = "root"; Database user Name
var $dbpass = ""; Database Password
var $conn; Database Company
function favorite () {
$this->methodtable = Array (
"Get_data" => Array (
"description" => "Returns data",
"Access" => "remote",
"ReturnType" => "Recordset"//Return data to DataSet (the example is a string)
),
"Append" => Array (
"description" => "Inserts a Data",
"Access" => "remote",
"Arguments" => Array ("name", "url"),//requires two parameters
"ReturnType" => "String"
),
);
Connecting to a database
$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);
}
/**
* Implementation of Added functionality
* @ $name: Favorite site Name
* @ $url: Web site
*/
function append ($name, $url) {
$rs = mysql_query (INSERT into Tbl_favorite (webname,url) VALUES ('. $name. "', '. $url."));
if (Mysql_error ()) return "error";
else return $name;
}
/***
* Realize read function
* Return: Array
*/
function Get_data () {
Return mysql_query ("SELECT * from Tbl_favorite");
}
}
Debug
$f = new Favorite;
Print_r ($f->get_data ());
$f->append ("korptons blog", "http://www.oiasoft.com");
?>
One less MySQL:--phpMyAdmin SQL Dump
--Version 2.8.2
--Http://www.phpmyadmin.net
--
--Host: localhost
--Date Created: April 08, 2007 13:04
--Server version: 5.0.19
--PHP version: 5.0.4
--
--database: ' Favorite '
--
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.