1. Go to this page and download the library: Download dynamonet/query-builder 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/ */
dynamonet / query-builder example snippets
use Dynamo\QueryBuilder\SqlQueryBuilder as Query;
$users = (new Query)
->select('*') // This is the default select
->from('users u')
->leftJoin('posts p',[
'p.user_id = u.id',
'p.trashed' => null
]) // translates to: LEFT JOIN posts p ON p.user_id = u.id AND p.trashed IS NULL
->where([
'role' => 'ADMIN', // translates to "role = ?", where "?" will be securely replaced by the PDO layer
"age > $minAge", // insecure! $minAge will not be prepared! However, we allow this form for convenience
'age >' => $minAge, // better, and prepareable
[ 'age', '<=', $maxAge ], // field-operator-value array if you prefer
'age BETWEEN' => [ $minAge, $maxAge ], // even better
], false) // false "OR's" all the previous conditions. Default is true, which will "AND" all the conditions
->fetchAll(); // Fetches all the results
use Dynamo\QueryBuilder\SqlQueryBuilder as Query;
....
$pdo = new \PDO('mysql:dbname=mydb;host=localhost;charset=utf8', 'myuser', 'mypass');
$query = (new Query($pdo))
Query::setPdo($pdo);
....
$query = (new Query()) // this will use the static PDO instance.
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.