Oihana PHP Arango

aqlLimit.php

Table of Contents

Functions

aqlLimit()  : string
Provides helpers to build AQL `LIMIT` clauses for ArangoDB queries, supporting **offsets**, **parameter binding**, and **dynamic query generation**.

Functions

aqlLimit()

Provides helpers to build AQL `LIMIT` clauses for ArangoDB queries, supporting **offsets**, **parameter binding**, and **dynamic query generation**.

aqlLimit(int $limit[, int $offset = 0 ][, array<string|int, mixed>|null &$binds = null ]) : string

The LIMIT clause in ArangoDB is used to:

  • Restrict the number of results returned by a query.
  • Optionally skip a number of documents using an offset.
  • Use bind parameters instead of hardcoded values to improve performance and prevent query plan cache invalidation. AQL Syntax*
LIMIT <count>
LIMIT <offset>, <count>

Why use bind parameters for LIMIT/OFFSET?*

Using placeholders like @limit and @offset allows ArangoDB to reuse the same query execution plan instead of recompiling it each time. This is particularly efficient when paginating through large datasets.

Examples:

// Simple limit
echo aqlLimit(10);
// LIMIT 10

// Limit with offset
echo aqlLimit(10, 5);
// LIMIT 5, 10

// Limit with bound parameters
$binds = [];
echo aqlLimit(10, 5, $binds);
// LIMIT @offset, @limit
// $binds = [ 'limit' => 10 , 'offset' => 5 ]
Parameters
$limit : int

Maximum number of results to return. Must be > 0 to generate a clause.

$offset : int = 0

Number of results to skip before starting to return results (default 0).

$binds : array<string|int, mixed>|null = null

Optional reference to a binds array for parameterized queries.

Tags
throws
BindException

If parameter binding fails.

since
1.0.0
author

Marc Alcaraz

Return values
string

AQL LIMIT clause string, or empty string if $limit <= 0.

On this page

Search results