1. Go to this page and download the library: Download initorm/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/ */
initorm / query-builder example snippets
use InitORM\QueryBuilder\QueryBuilder;
$qb = new QueryBuilder('mysql');
$sql = $qb
->select('u.id', 'u.name')
->from('users AS u')
->where('u.status', 1)
->andWhere('u.country', 'TR')
->orderBy('u.id', 'DESC')
->limit(20)
->generateSelectQuery();
// $sql ─────────────────────────────────────────────────────────────────
// SELECT `u`.`id`, `u`.`name`
// FROM `users` AS `u`
// WHERE `u`.`status` = 1 AND `u`.`country` = :country
// ORDER BY `u`.`id` DESC
// LIMIT 20
$pdo = new PDO('mysql:host=localhost;dbname=app', 'app', 'secret');
$stmt = $pdo->prepare($sql);
$stmt->execute($qb->getParameter()->all());
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$qb->select('u.name')
->from('users AS u')
->whereIn('u.id', $qb->subQuery(function (QueryBuilder $sub) {
$sub->select('id')->from('roles')->where('name', 'admin');
}));
// SELECT `u`.`name` FROM `users` AS `u`
// WHERE `u`.`id` IN (SELECT `id` FROM `roles` WHERE `name` = :name)
$qb->select('p.title', 'u.name')
->from('posts AS p')
->innerJoin('users AS u', function (QueryBuilder $j) {
$j->on('u.id', 'p.user_id')
->where('u.active', 1);
});
$qb->from('posts')
->set(['id' => 1, 'title' => 'First', 'views' => 100])
->set(['id' => 2, 'title' => 'Second', 'views' => 42]);
echo $qb->generateUpdateBatchQuery('id');
// UPDATE `posts`
// SET `title` = CASE WHEN `id` = 1 THEN :title WHEN `id` = 2 THEN :title_1 ELSE `title` END,
// `views` = CASE WHEN `id` = 1 THEN 100 WHEN `id` = 2 THEN 42 ELSE `views` END
// WHERE `id` IN (1, 2)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.