AQL is a PHP extension that automatically transforms SQL strings into structured data at compile-time using AST hooks.
- Zero Runtime Overhead: SQL parsing happens at compile-time (once per file)
- Automatic Detection: Detects SQL queries by keywords (SELECT, INSERT, UPDATE, DELETE, etc.)
- Heredoc Support: Works with both heredoc and nowdoc syntax
- String Prefix Detection: Automatically detects SQL in regular strings
<?php
// Regular string with SQL - automatically detected
$query = "SELECT * FROM users WHERE id = ?";
// After AQL processing, $query becomes:
// [
// '__aql_query' => true,
// 'sql' => "SELECT * FROM users WHERE id = ?"
// ]<?php
$query = <<<SQL
SELECT u.name, u.email
FROM users u
WHERE u.active = true
SQL;
// Also transformed into an arraycd /path/to/php-src/ext/aql
phpize
./configure
make
make installAdd to php.ini:
extension=aql.so
aql.enabled=1aql.enabled- Enable/disable AQL processing (default: 1)
- AST hook integration
- String detection by SQL keywords
- Basic array generation
- Implement full SQL parser
- Generate structured AST for SQL
- Support for:
- SELECT statements
- INSERT statements
- UPDATE statements
- DELETE statements
- JOIN operations
- WHERE conditions
- ORDER BY, GROUP BY, LIMIT
- Parameter binding detection
- Query optimization hints
- Custom DSL extensions
- IDE integration support
<?php
$query = "SELECT id, name FROM users WHERE active = 1";
// After AQL transformation:
var_dump($query);
/*
array(2) {
["__aql_query"]=>
bool(true)
["sql"]=>
string(42) "SELECT id, name FROM users WHERE active = 1"
}
*/AQL uses zend_ast_process hook to intercept the Abstract Syntax Tree after parsing but before compilation. This allows:
- Compile-time processing - no runtime overhead
- Full AST manipulation - can replace any node
- Opcache compatible - transformed code is cached
bool aql_is_sql_string(zend_string *str) {
// Skip leading whitespace
// Check first 4-6 characters for SQL keywords:
// SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP
}PHP License 3.01
Built for TrueAsync PHP project