开发者

How do you supply the parameters int[] in a Flex PHP Service

开发者 https://www.devze.com 2023-03-24 10:48 出处:网络
My Flex Service Call is returning Null can anybody tell me where I am going wrong? Database: user_id: 1

My Flex Service Call is returning Null can anybody tell me where I am going wrong?

Database:

user_id: 1 
user_name: stephen
user_password: qwerty
status: Active

user_id: 2 
user_name: 开发者_运维问答john
user_password: qwerty
status: Passive

user_id: 3 
user_name: marice
user_password: qwerty
status: Awaiting

user_id: 4
user_name: maria
user_password: qwerty
status: Passive

PHP Service Method:

public function getAllUserByStatus($arrStatus) {

    $rows = array();

    foreach ($arrStatus as $item)
    {
        $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename WHERE status=?");     
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 's', $item);      
        $this->throwExceptionOnError();

        mysqli_stmt_execute($stmt);
        $this->throwExceptionOnError();

        mysqli_stmt_bind_result($stmt, $row->user_id, $row->user_name, $row->user_password, $row->status);

        while (mysqli_stmt_fetch($stmt)) {
          $rows[] = $row;
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt, $row->user_id, $row->user_name, $row->user_password, $row->status);
        }

        mysqli_stmt_free_result($stmt);
    }

    mysqli_close($this->connection);
    return $rows;
}

PHP Test Query:

<?php 
    include('UserService.php'); 
    $o = new UserService(); 
?>

<pre>
<?php 
    var_dump($o->getAllUserByStatus(array('Active','Passive')));
?>
</pre>

PHP Test Result:

array
  0 => 
    object(stdClass)[4]
      public 'user_id' => int 1
      public 'user_name' => string 'stephen' (length=7)
      public 'user_password' => string 'qwerty' (length=6)
      public 'status' => string 'Active' (length=6)
  1 => 
    object(stdClass)[5]
      public 'user_id' => int 2
      public 'user_name' => string 'john' (length=4)
      public 'user_password' => string 'qwerty' (length=6)
      public 'status' => string 'Passive' (length=7)
  2 => 
    object(stdClass)[3]
      public 'user_id' => int 4
      public 'user_name' => string 'maria' (length=5)
      public 'user_password' => string 'qwerty' (length=6)
      public 'status' => string 'Passive' (length=7)

Flex Application (Returns Null, Why):

<?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"
               xmlns:userservice="services.userservice.*"
               minWidth="955" minHeight="600"     creationComplete="application1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.events.FlexEvent;
            import mx.rpc.events.ResultEvent;

            protected var acUser:ArrayCollection;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                getAllUserByStatusResult.token = userService.getAllUserByStatus(new ArrayCollection(new Array(['Active','Passive'])));
                getAllUserByStatusResult.addEventListener(ResultEvent.RESULT, getAllUserByStatusResultHandler);
            }

            protected function getAllUserByStatusResultHandler(event:ResultEvent):void
            {
                acUser = event.result as ArrayCollection;

                // Break Point to examine acUser
        }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:CallResponder id="getAllUserByStatusResult"/>
        <userservice:UserService id="userService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
</s:Application>


If the event.result is not an ArrayCollection, then trying to cast it to one will just lead to a null assignment. Try making acUser an instance of Array and cast your event.result to that.

0

精彩评论

暂无评论...
验证码 换一张
取 消