1. Go to this page and download the library: Download blues911/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/ */
blues911 / query-builder example snippets
use QueryBuilder\Builder as DB;
// init connection
$db = new DB([
'mysql:dbname=test;host=localhost;port=3306;charset=utf8',
'root',
'password'
]);
// query all
$db->query("SELECT * FROM users")
->build()
->fetchAll();
// query one
$db->query("SELECT * FROM users WHERE id=:id")
->bindParams(['id', 1])
->build()
->fetch();
// count
$db->query("SELECT * FROM users")
->build()
->rowCount();
// debug params
$db->query("SELECT * FROM users WHERE status=:status AND role=:role")
->bindParams([
['status', 1],
['role', 'admin']
])
->build()
->debugParams();