ADOdb Library for PHP Manual
Prev SelectLimit Next

SelectLimit($sql,$numrows=-1,$offset=-1,$inputarr=false)

Returns a recordset if successful. Returns false otherwise. Performs a select statement, simulating PostgreSQL's SELECT statement, LIMIT $numrows OFFSET $offset clause.

In PostgreSQL, SELECT * FROM TABLE LIMIT 3 will return the first 3 records only. The equivalent is $connection->SelectLimit('SELECT * FROM TABLE',3). This functionality is simulated for databases that do not possess this feature.

And SELECT * FROM TABLE LIMIT 3 OFFSET 2 will return records 3, 4 and 5 (eg. after record 2, return 3 rows). The equivalent in ADOdb is $connection->SelectLimit('SELECT * FROM TABLE',3,2).

Note that this is the opposite of MySQL's LIMIT clause. You can also set $connection->SelectLimit('SELECT * FROM TABLE',-1,10) to get rows 11 to the last row.

The last parameter $inputarr is for databases that support variable binding such as Oracle oci8. This substantially reduces SQL compilation overhead. Below is an Oracle example:

    $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=:val", 100,-1,array('val'=> $val));;

The oci8po driver (oracle portable driver) uses the more standard bind variable of ?:

    $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=?", 100,-1,array('val'=> $val));

Ron Wilson reports that SelectLimit does not work with UNIONs.


Prev Home Next
ExecuteCursor Up CacheSelectLimit

Sponsored by phpLens