PHP code example of monkeyscloud / monkeyslegion-query
1. Go to this page and download the library: Download monkeyscloud/monkeyslegion-query library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
monkeyscloud / monkeyslegion-query example snippets
$qb->from('users')
->where('status', '=', 'active') // standard
->orWhere('role', '=', 'admin') // OR
->whereIn('id', [1, 2, 3]) // IN
->whereNotIn('status', ['banned']) // NOT IN
->whereBetween('age', 18, 65) // BETWEEN
->whereNull('deleted_at') // IS NULL
->whereNotNull('email') // IS NOT NULL
->get();
use MonkeysLegion\Query\Query\CteBuilder;
$cte = new CteBuilder();
$cte->add('active_users', 'SELECT * FROM users WHERE status = ?', ['active']);
// Recursive CTE (tree structures)
$cte->add(
name: 'category_tree',
sql: 'SELECT id, parent_id FROM categories WHERE id = ? '
. 'UNION ALL '
. 'SELECT c.id, c.parent_id FROM categories c '
. 'JOIN category_tree ct ON c.parent_id = ct.id',
bindings: [$rootId],
recursive: true,
);