针对MySQL搜索问题的Flex 4.5 PHP类

针对MySQL搜索问题的Flex 4.5 PHP类,php,mysql,apache-flex,air,adobe,Php,Mysql,Apache Flex,Air,Adobe,我有一个简单的MySQL 5数据库,包括 id-Int-主键 userID-int 投影整数 注-varchar 120 还有一个简单的Flex4.5应用程序,我需要在userID表中搜索属于某个userID的所有行,并将其返回到Flex应用程序。我正在使用默认的ZendAMF进行远程处理。当前我的类看起来像: public function getAllBookmarksByUser($userId) { $stmt = mysqli_prepare($this->co

我有一个简单的MySQL 5数据库,包括

id-Int-主键 userID-int 投影整数 注-varchar 120 还有一个简单的Flex4.5应用程序,我需要在userID表中搜索属于某个userID的所有行,并将其返回到Flex应用程序。我正在使用默认的ZendAMF进行远程处理。当前我的类看起来像:

public function getAllBookmarksByUser($userId) {

        $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename WHERE userId=?");     
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 'i', $itemID);        
        $this->throwExceptionOnError();

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

        $rows = array();

        mysqli_stmt_bind_result($stmt, $row->id, $row->userId, $row->projectID, $row->note);

        while (mysqli_stmt_fetch($stmt)) {
          $rows[] = $row;
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt, $row->id, $row->userId, $row->projectID, $row->note);
        }

        mysqli_stmt_free_result($stmt);
        mysqli_close($this->connection);

        return $rows;
    }
但是,它不起作用。在Flash Builder 4.5中测试时不返回任何对象,即使我知道条目在db中

我做错了什么

编辑 这是一个AdobeAIR移动应用程序

编辑

我在同一个文件中添加了一个PHP类,该类也工作得很好。以下是完整的文件:

<?php

/**
 * Get 
 */
class BookmarksService {

    var $username = "*SQLUserName";
    var $password = "*SQLUserPassword*";
    var $server = "*MySQLServerURL*";
    var $port = "3306";
    var $databasename = "mscoast";
    var $tablename = "bookmarks";

    var $connection;

    /**
     * Connect
     */
    public function __construct() {
        $this->connection = mysqli_connect(
                                $this->server,  
                                $this->username,  
                                $this->password, 
                                $this->databasename,
                                $this->port
                            );

        $this->throwExceptionOnError($this->connection);
    }

    /**
     *Get All
     */
    public function getAllBookmarks() {

        $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");        
        $this->throwExceptionOnError();

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

        $rows = array();

        mysqli_stmt_bind_result($stmt, $row->id, $row->userId, $row->projectID, $row->note);

        while (mysqli_stmt_fetch($stmt)) {
          $rows[] = $row;
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt, $row->id, $row->userId, $row->projectID, $row->note);
        }

        mysqli_stmt_free_result($stmt);
        mysqli_close($this->connection);

        return $rows;
    }


    /**
     * Get All By User ID
     */

public function getAllBookmarksByUser($userId) {

        $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename WHERE userId=?");      
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 'i', $itemID);      
        $this->throwExceptionOnError();

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

        $rows = array();

        mysqli_stmt_bind_result($stmt, $row->id, $row->userId, $row->projectID, $row->note);

        while (mysqli_stmt_fetch($stmt)) {
          $rows[] = $row;
          $row = new stdClass();
          mysqli_stmt_bind_result($stmt, $row->id, $row->userId, $row->projectID, $row->note);
        }

        mysqli_stmt_free_result($stmt);
        mysqli_close($this->connection);

        return $rows;
    }


    /**
     * Utility function to throw an exception if an error occurs 
     * while running a mysql command.
     */
    private function throwExceptionOnError($link = null) {
        if($link == null) {
            $link = $this->connection;
        }
        if(mysqli_error($link)) {
            $msg = mysqli_errno($link) . ": " . mysqli_error($link);
            throw new Exception('MySQL Error - '. $msg);
        }       
    }
}

?>
答复:


首先用如下打印方式检查return语句

print_r($rows);
如果打印行,则可能存在连接问题 然后,您需要在运行时使用Firebug检查请求响应 flex调用该服务。检查请求-响应很简单, 它位于tab net->All in Firebug下


检查您得到的响应并相应地纠正错误

如果问题已经解决,很抱歉,但这是因为您向函数提供了$userID,但绑定了不同的变量吗$项目ID

getAllBookmarksByUser$userId


mysqli_stmt_bind_param$stmt,'i',$itemID

我想我应该指定这是一个Adobe AIR应用程序,因此我不能在Firebug中调试它…哦,因为你可以在浏览器中用print_r语句检查php。return语句不返回任何行。与mysql服务器的连接非常方便。我在PHP文件中还有另外三个类,它们可以很好地连接并返回结果。
HTTP/1.1 200 OK
Date: Mon, 21 Nov 2011 19:03:45 GMT
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.3
Cache-Control: no-cache, must-revalidate
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Content-Length: 289
Content-Type: application/x-amf

Flex Message (flex.messaging.messages.AcknowledgeMessage)     clientId = 2FE53654-02C4-3548-136C-000066519473    correlationId = A43315C8-6A13-4BAB-9F70-C78337A6AA5A    destination = null    messageId = 5FCFFE5B-EBA5-2AE9-2A51-00005691367F    timestamp = 132190222500    timeToLive = 0    body = []
print_r($rows);