• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Enrique Chavez

Professional WordPress Development

  • Home
  • Blog
  • Contact Me
  • Hire Me

Resultset de PHP a Flash sin escalas

ActionScript, AMFPHP · May 17, 2005

Ahora con la nueva version de AMFPHP es posible enviar un resultset directamente a Flash desde PHP.

Lo unico que hay que hacer es, el query en PHP y enviar el resultset a FLASH asi de simple.

Servicio resultset.php

[php]
methodTable = array(
“getData” => array(
“description” => “Regresa un Resultset”,
“access” => “remote”
),
“conect” => array(
“description” => “Conecta a la base de datos”,
“access” => “private”
)
);
}
function conecta() {
$host = “tuHost”;
$username = “tuUsuario”;
$passwd = “tuPassword”;
$database = “nombreDeTuBaseDeDatos”;
$con = mysql_connect($host, $username, $passwd);
mysql_select_db($database, $con);
return $con;
}
function getData(){
$con = $this->conecta();
$table = “tuTabla”
$sql = “select * from $table order by id DESC”;
$res = mysql_query($sql);
mysql_close($con);
return $res;
}
}
[/php]

Llamando al servicio resultset desde Flash

[as]
import mx.remoting.Service;
import mx.rpc.FaultEvent;
import mx.remoting.PendingCall;
import mx.rpc.ResultEvent;
import mx.rpc.RelayResponder;
//Cambia por la ruta a tu gateway
var urlGateway:String = “http://www.tmeister.dev/amfphp/gateway.php”;
var services:String = “resultset”;
var myService:Service = new Service(urlGateway, null, services, null, null);
var calling:PendingCall = myService.getData();
calling.responder = new RelayResponder(this, “getData_Result”);
function getData_Result(obj:ResultEvent) {
rows = obj.result._items;
for (var info in rows) {
trace(“id => “+rows[info].id);
trace(“name => “+rows[info].name);
trace(“description => “+rows[info].description);
trace(“price => “+rows[info].price);
trace(“————————————–“);
}
}
[/as]

por ultimo la estructura de nuestra tabla

[sql]
CREATE TABLE products (
id int(11) NOT NULL auto_increment,
name varchar(255) NOT NULL default ”,
description text NOT NULL,
price varchar(6) NOT NULL default ”,
PRIMARY KEY (id)
) TYPE=MyISAM;
INSERT INTO products VALUES (1, ‘Evanescence Anywhere But Home (w/ bonus DVD)’, ‘a little description’, ‘22.99’);
INSERT INTO products VALUES (2, ‘Evanescence ORIGIN’, ‘Description here… : P’, ‘10.88’);
INSERT INTO products VALUES (3, ‘Evanescence Fallen’, ‘Another good CD.’, ‘13.49’);
[/sql]

Descarga Archivos

enjoy 😀

Related

Filed Under: ActionScript, AMFPHP Tagged With: ActionScript, AMFPHP

Enrique Chavez

Senior Full Stack WordPress developer & WordPress Enthusiast -
Spend my days building cool stuff with WordPress.

Reader Interactions

Comments

  1. Alan says

    Mar 24, 2007 at 12:51 pm

    Hola, estoy probando el ejemplo pero no me funciona. Ya cambie del php el host, usuario, passwd, base y tabla. Del .fla cambie el path al gateway e incorpore los dos componentes de remoting pero no me funciona la consulta. Que puede ser?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Footer

SUBSCRIBE FOR UPDATES

Like what you’ve read? If you're interested in my email, sign up here. No spam I promise!

My WordPress Plugins

  • JWT for WP REST API
  • WP Simple Mail Sender
  • Idea Factory

My SideProjects

  • WordPress Plugin Boilerplate Generator

My Profiles

  • WordPress
  • GitHub
  • Linkedin

Additional Info

  • Blog
  • Hire Me
  • Contact Me

© 2021 Enrique Chavez