1. Go to this page and download the library: Download jpi/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/ */
jpi / query example snippets
$queryBuilder = new \JPI\Database\Query\Builder($database, $table);
// Join with a single expression, but can add more to the 2nd parameter
$queryBuilder->join("orders", "users.id = orders.user_id");
// Nicer syntax adding multiple expressions
$queryBuilder->join(
$queryBuilder->newJoinClause("orders")
->on("users.id = orders.user_id")
->on("orders.status = 'completed'")
);
$queryBuilder->where("status", "=", "active");
$queryBuilder->where("age", ">", 18);
$queryBuilder->where("name", "LIKE", "%john%");
// If you need to control the parameter name yourself (for example, to reuse it across multiple
// conditions), prefix the placeholder with `:` and then bind it explicitly using `param()`:
$queryBuilder->where("status", "=", ":status_value");
$queryBuilder->param("status_value", "active");
// age BETWEEN 18 AND 65
$queryBuilder->where("age", "BETWEEN", [18, 65]);
$queryBuilder->where("deleted_at", "IS NULL");
$queryBuilder->where("email", "IS NOT NULL");
// id IN (SELECT customer_id FROM orders WHERE status = 'completed')
$subQuery = new \JPI\Database\Query\Builder($database, "orders");
$subQuery
->column("customer_id")
->where("status", "=", "completed");
$queryBuilder->where("id", "IN", $subQuery);
// SELECT COUNT(*) as count FROM users;
$count = $queryBuilder->count();
// $count = 10;
// SELECT COUNT(*) as count FROM users WHERE status = "active";
$count = $queryBuilder
->where("status", "=", "active")
->count();
// $count = 5;
// SELECT COUNT(email) as count FROM users;
// Using column parameter to count non-NULL values in the email column
$count = $queryBuilder->count("email");
// $count = 10;
// SELECT COUNT(DISTINCT status) as count FROM users;
// Can use expressions in the column parameter
$count = $queryBuilder->count("DISTINCT status");
// $count = 2;