1. Go to this page and download the library: Download absorbing/cql-core 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/ */
absorbing / cql-core example snippets
QL\CQL;
// Create a CQL instance
$cql = new CQL();
// Execute a query
$results = $cql->execute("
DEFINE 'users.csv' AS users WITH HEADERS
SELECT name, age
FROM users
WHERE age > 25
");
// Iterate over results
foreach ($results as $row) {
echo "{$row['name']} is {$row['age']} years old\n";
}
// Or use convenience methods
$array = $cql->query($query); // Returns array
$first = $cql->first($query); // Returns first row
$count = $cql->count($query); // Returns count
$cql = new CQL();
$affected = $cql->statement("
DEFINE 'users.csv' AS users WITH HEADERS
UPDATE users SET age = age + 1 WHERE name = 'Alice'
");
// execute() also accepts write statements, returning a Collection:
// [['affected_rows' => 1]]
use CQL\CQL;
// users.csv:
// id,name,age,status
// 1,Alice,30,active
// 2,Bob,25,inactive
// 3,Charlie,35,active
$cql = new CQL();
$results = $cql->execute("
DEFINE 'users.csv' AS users WITH HEADERS
SELECT name, age
FROM users
WHERE age >= 30 AND status = 'active'
");
// Output:
// {"name":"Alice","age":"30"}
// {"name":"Charlie","age":"35"}
use CQL\CQL;
// users.csv:
// id,name
// 1,Alice
// 2,Bob
// orders.csv:
// order_id,user_id,product,amount
// 101,1,Laptop,1200
// 102,1,Mouse,25
// 103,2,Keyboard,75
$cql = new CQL();
$results = $cql->execute("
DEFINE 'users.csv' AS users WITH HEADERS
DEFINE 'orders.csv' AS orders WITH HEADERS
SELECT users.name, orders.product, orders.amount
FROM users
JOIN orders ON users.id = orders.user_id
WHERE orders.amount > 50
");
// Output:
// {"users.name":"Alice","orders.product":"Laptop","orders.amount":"1200"}
// {"users.name":"Bob","orders.product":"Keyboard","orders.amount":"75"}
use CQL\CQL;
$cql = new CQL();
$results = $cql->execute("
DEFINE 'employees.csv' AS emp WITH HEADERS
SELECT emp.first_name AS name, emp.salary AS pay
FROM emp
WHERE emp.department = 'Engineering'
");
// Output uses aliased column names:
// {"name":"John","pay":"95000"}
// {"name":"Jane","pay":"105000"}
use CQL\CQL;
// products.csv:
// name,price,quantity
// Widget,10.50,100
// Gadget,25.00,50
// Doohickey,5.75,200
$cql = new CQL();
$results = $cql->execute("
DEFINE 'products.csv' AS products WITH HEADERS
SELECT name, price, quantity
FROM products
WHERE price * quantity > 1000
");
// Output:
// {"name":"Gadget","price":"25.00","quantity":"50"}
// {"name":"Doohickey","price":"5.75","quantity":"200"}
use CQL\CQL;
// For large CSV files (>50MB), use streaming mode to reduce memory usage
// Explicit streaming
$cql = CQL::streaming();
$results = $cql->execute("
DEFINE 'large_dataset.csv' AS data WITH HEADERS
SELECT id, name, value
FROM data
WHERE value > 1000
");
// Automatic mode (recommended) - decides based on file size
$cql = CQL::auto();
$results = $cql->execute($query);
// Custom threshold
$cql = CQL::auto(10 * 1024 * 1024); // 10MB threshold
$results = $cql->execute($query);