0 Replies Latest reply on Feb 24, 2011 7:37 AM by willise414

    Zend + FB + MySQL problem

    willise414 Level 1

      Hi all,


      I am trying to teach myself the Zend connection to my database with a simple FB4 example, but I can't get it to work at all. It may be something simple, but I can't for the life of me, see it.


      This is my MXML code:


      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
                <!-- Place non-visual elements (e.g., services, value objects) here -->
                <s:ChannelSet id="zend_amf_channel_set">
                          <s:AMFChannel uri="http://www.localhost/gateway.php"/>
                <s:RemoteObject id="family_VO" destination="zend-amf" source="family" 
                     <s:method name="getAllMembers" result="getAllMembersResult(event)"/>
                     import mx.controls.Alert;
                     import mx.events.FlexEvent;
                     import mx.rpc.events.FaultEvent;
                     import mx.rpc.events.ResultEvent;
                     //private const GATEWAY_URL:String = "c:\wamp\www\WilliamsFamily\gateway.php";
                     private var memberData:MemberData;
                     private var lang_title:String = "My Attempt To Figure This Stuff Out!";
                     protected function getAllMembers():void
                     protected function clearDataGrid():void
                          member_dg.dataProvider = {};     
                     protected function getAllMembersResult(e:ResultEvent):void
                          member_dg.dataProvider = e.result;
                     protected function membersError(e:FaultEvent):void
           <s:VGroup   width="100%" horizontalAlign="center" paddingTop="25">
                <s:Label text ="{lang_title}" fontSize="20"/>
                <mx:DataGrid id="member_dg" height="100">
                          <mx:DataGridColumn headerText="ID" dataField="id" width="100"/>
                          <mx:DataGridColumn headerText="First Name" dataField="fname"/>
                          <mx:DataGridColumn headerText="Last Name" dataField="lname"/>
                          <mx:DataGridColumn headerText="Age" dataField="age"/>
                          <mx:DataGridColumn headerText="Gender" dataField="gender" width="200"/>
                     <s:Button label="Get Family Members" click="{getAllMembers();}"/>
                     <s:Button label="Clear" click="{clearDataGrid();}"/>


      The family.php



      require_once 'MemberData.php';
      class Family
           public function __construct()
                mysql_connect("localhost", "root", "root");
           public function getAllMembers()
                //Array of family members
                $members = array();
                //Select all fields from db table
                $result = mysql_query("SELECT * FROM family");
                //if successfuly, go through results
                while ($row = mysql_fetch_assoc($result))
                     //create family member value object and populate with values
                     $member = new MemberData();
                     $member->id = $row["id"];
                     $member->fname = $row["fname"];
                     $member->lname = $row["lname"];
                     $member->age = $row["age"];
                     $member->gender = $row["gender"];
                     array_push($members, $member);
           //return the array of family members to flex
           return $members;






      class MemberData
           public $id;
           public $fname;
           public $lname;
           public $age;
           public $gender;






      $debug = true;
      if ($debug)
           ini_set("display_errors", "on");
           ini_set("display_errors", "off");
      require_once "Zend/Amf/Server.php";
      $server = new Zend_Amf_Server();
      require_once "family.php";
      $server->setClassMap("MemberData", "MemberData");




      I was following a tutorial I found that seemed to explain the Zend+WAMP setup fairly well. I changed the php.ini include path to point to teh Zend/Library.


      It seems like I am not connecting to the database at all. Anyone see problems with the code?


      Thanks a million for the help!!