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

    Zend + FB + MySQL problem

    willise414

      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:s="library://ns.adobe.com/flex/spark" 
                        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
           <fx:Declarations>
                <!-- Place non-visual elements (e.g., services, value objects) here -->
                
                <s:ChannelSet id="zend_amf_channel_set">
                     <s:channels>
                          <s:AMFChannel uri="http://www.localhost/gateway.php"/>
                     </s:channels>
                </s:ChannelSet>
                
                <s:RemoteObject id="family_VO" destination="zend-amf" source="family" 
                                    channelSet="{zend_amf_channel_set}"
                                    showBusyCursor="true"
                                    fault="membersError(event)">
                     <s:method name="getAllMembers" result="getAllMembersResult(event)"/>
                </s:RemoteObject>
                
                
           </fx:Declarations>
           
           <fx:Script>
                <![CDATA[
                     
                     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;
                     
                     [Bindable]
                     
                     private var lang_title:String = "My Attempt To Figure This Stuff Out!";
                     
                     protected function getAllMembers():void
                     {
                          family_VO.getAllMembers;
                     }
                     
                     protected function clearDataGrid():void
                     {
                          member_dg.dataProvider = {};     
                     }
                     
                     protected function getAllMembersResult(e:ResultEvent):void
                     {
                          member_dg.dataProvider = e.result;
                     }
                     
                     protected function membersError(e:FaultEvent):void
                     {
                          Alert.show(e.toString());
                     }
                     
                     
                ]]>
           </fx:Script>
           <s:VGroup   width="100%" horizontalAlign="center" paddingTop="25">
                
                <s:Label text ="{lang_title}" fontSize="20"/>
                
                <mx:DataGrid id="member_dg" height="100">
                     <mx:columns>
                          <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"/>
                          
                     </mx:columns>
                </mx:DataGrid>
                <s:HGroup>
                     <s:Button label="Get Family Members" click="{getAllMembers();}"/>
                     <s:Button label="Clear" click="{clearDataGrid();}"/>
                </s:HGroup>
           </s:VGroup>
      </s:Application>
      
       
      

       

      The family.php

       

       

      <?php
      
      require_once 'MemberData.php';
      
      
      
      class Family
      {
           public function __construct()
           {
                mysql_connect("localhost", "root", "root");
                mysql_select_db("williamsfamily");
           }
           
           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;
           }
      }
      
      
      ?>
      

       

       

      MemberData.php

       

       

      <?php 
      
      class MemberData
      
      {
           public $id;
           public $fname;
           public $lname;
           public $age;
           public $gender;
      }
      
      ?>
      

       

       

      gateway.php

       

       

      <?php
      
      $debug = true;
      
      if ($debug)
      {
           error_reporting(E_ALL|E_STRICT);
           ini_set("display_errors", "on");
      }
      
      else
      {
           ini_set("display_errors", "off");
      }
      
      require_once "Zend/Amf/Server.php";
      $server = new Zend_Amf_Server();
      
      require_once "family.php";
      $server->setClass("Family");
      
      $server->setClassMap("MemberData", "MemberData");
      
      echo($server->handle());
      
      ?>
      

       

       

       

      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!!