> > Unless a major upgrade has been done to amfphp, it does not support
> > (natively) pageable recordsets. I could be wrong though.

In fact, a major upgrade has been done. :)

I've successfully used the latest amfphp with ADODB for PHP, and it
works very well.  In your gateway.php, you need to add the adapter
mapping for adodb resultsets. Use whatever classname is associated
with the adodb connection type you are using.

$gateway->addAdapterMapping('adorecordset_mysql', 'adodb');

Then, make sure you have a DB connection open in your service
somewhere via and include or in the constructor or something...

Here, I use global $DB.

    // include adodb...
    require_once '/path/to/adodb/adodb.inc.php';
    // INIT ADODB CONNECTION
    global $DB;
    $DB = &ADONewConnection( 'mysql' );
    if( !is_object($DB) || !$DB->Connect( 'localhost', 'root', '',
'northwind') ) {
        NetDebug::trace("Unable to connect to database.  ".$DB->ErrorMsg());
    }

Then, along with your service method, you need to have a _count method
that can return the total number of records.  ADODB is nice as it has
paging functionality built in, but you need to convert from the offset
argument used with amfphp to the page number used by adodb's
PageExecute.  ($pageNum = ($limit+$offset)/$limit;)  Here is a sample
service...

/*
Pageable Recordset Demo with ADODB and MySQL
Database is MySQL port of Northwind DB.
*/

class Northwind {
    function Northwind() {
        $this->methodTable = array(
            "getProducts" => array("access"=>"remote", "pagesize"=>5)
        );
    }

    function getProducts($offset=0, $limit=5) {
        global $DB;
        $DB->SetFetchMode(ADODB_FETCH_ASSOC);
        $this->getProducts_countQuery = 'SELECT COUNT(*) FROM products';
        $sql = 'SELECT ProductID, ProductName, UnitPrice FROM products';
        $pageNum = ($limit+$offset)/$limit; // 1=first page, 2=second page
        if($rs = $DB->PageExecute($sql, $limit, $pageNum) {
            return $rs;
        } else {
            NetDebug::trace( $DB->ErrorMsg() );
            return false;
        }
    }

    function getProducts_count() {
        global $DB;
        return $DB->GetOne( $this->getProducts_countQuery );
    }
}


//---------------

-david knape
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to