Flash background Data Connection (PHP article) Php&flash Favorites---amfphp implementation +mysql

Source: Internet
Author: User
Tags insert log mysql phpmyadmin
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 structure of the table ' Tbl_favorite '
--

CREATE TABLE ' Tbl_favorite ' (
' ID_PK ' int (one) unsigned not NULL auto_increment,
' webname ' varchar not NULL,
' url ' varchar not NULL,
' Timeline ' timestamp not NULL default current_timestamp on Update Current_timestamp,
PRIMARY KEY (' ID_PK ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=5;

--
--Export the data in the table ' Tbl_favorite '
--

INSERT into ' tbl_favorite ' (' id_pk ', ' webname ', ' url ', ' Timeline ') VALUES (1, ' Korptons blog ', ' http://www.oiasoft.com/', ' 2007-04-08 12:21:17 '),
(2, ' Yahoo ', ' http://cn.yahoo.com ', ' 2007-04-08 12:12:33 '),
(3, ' KK ', ' http://ww ', ' 2007-04-08 12:45:33 '),
(4, ' KFC ', ' http://www.kfc.com.cn ', ' 2007-04-08 12:46:52 ');

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.