如何使用数据服务(PHP/mySQL/flex 4.5)在flex 4.5中绑定查询结果

如何使用数据服务(PHP/mySQL/flex 4.5)在flex 4.5中绑定查询结果,php,mysql,apache-flex,flex4.5,Php,Mysql,Apache Flex,Flex4.5,我正在尝试将一个变量与通过以下PHP脚本执行的查询结果绑定: <?php //conection info define("DATABASE_SERVER", "localhost"); define("DATABASE_PORT", "3306"); define("DATABASE_USERNAME", "root"); define("DATABASE_PASSWORD", "root"); define("DATABASE_NAME", "e5001"); class Espo

我正在尝试将一个变量与通过以下PHP脚本执行的查询结果绑定:

<?php

//conection info
define("DATABASE_SERVER", "localhost");
define("DATABASE_PORT", "3306");
define("DATABASE_USERNAME", "root");
define("DATABASE_PASSWORD", "root");
define("DATABASE_NAME", "e5001");

class EsporteService
{
    private $_pdo;

    public function __construct() {
        try {
            $this->_pdo = new PDO('mysql:host='.DATABASE_SERVER.';port='.DATABASE_PORT.';dbname='.DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD);

        } catch(PDOException $e) {
            throw($e);
        }
    }


    /**
     * 
     * @return array[Esporte]
     */
    public function getEsportes()
    {
        $query = 'SELECT * FROM esporte_tb';            
        $stmt = $this->_pdo->query($query);
        return $stmt->fetchAll(PDO::FETCH_CLASS,'Esporte');
    }
}

我尝试了很多不同的方法,创建了一个可绑定的变量,如Array、ArrayCollection、Object等,但都没有成功

我试图解析查询并获取其长度,基于标签“teste”是否可见

有什么想法吗

非常感谢,


Gines

它看起来非常简单,不必要地复杂,但我建议您在Php中回答这个问题,然后在Php文件中使用Xml将其发送回FLEX,就像您在读写MySQL数据库时所做的那样。在您的情况下,它只是一个文本字段,在FLEX中作为答案字段是必需的!。在我看来,你的代码很好。您应该尝试在调试器中查看它。但是,您可能想做的是尝试执行异步调用。
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:consultaservice="services.consultaservice.*"
        xmlns:esporteservice="services.esporteservice.*"
        title="HomeView" creationComplete="view1_creationCompleteHandler(event)">
    <fx:Script>

        <![CDATA[
            import mx.events.FlexEvent;

            protected function view1_creationCompleteHandler(event:FlexEvent):void
            {
                getEsportesResult.token = esporteService.getEsportes();
            }

        ]]>
        </fx:Script>
    <fx:Declarations>
        <s:CallResponder id="getEsportesResult"/>
        <esporteservice:EsporteService id="esporteService"/>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:VGroup x="10" y="10" width="100%" height="100%" horizontalAlign="center">
        <s:Image x="100" width="179" height="125" source="assets/spadotto_logo.jpg"/>
        <s:List id="list" height="40%" 
                dataProvider="{getEsportesResult.lastResult}"
                labelField="esp_desc"
                change="navigator.pushView(TreinosDetails, list.selectedItem)"/>
        <s:Label id="teste" />

    </s:VGroup>
</s:View>