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]
enjoy 😀
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?