Download the PHP package jpi/query without Composer
On this page you can find all versions of the php package jpi/query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package query
Query
USE AT YOUR OWN RISK!
I would advise against using this on production applications...but feel free to use in your own personal / demo / experimental projects.
A simple library to make querying a database easier it works as a middleman between the application and a database.
This has been kept very simple stupid (KISS), other than type errors from PHP there is no validation, it will assume you are using it correctly. So please make sure to add your own validation if using user inputs in these queries.
Dependencies
- PHP 8.0+
- Composer
- PHP PDO
- MySQL 5+
- jpi/database v2
Installation
Use Composer
Usage
To create an instance, you will need an instance of \JPI\Database
(if unfamiliar you can read about that here) which is the first parameter, and the database table name as the second parameter. The same instance can be used multiple times as long as it's for the same database.
Action Methods:
These are the methods to call to end with select
, count: int
, insert($values array): int|null
, update($values array): int
& delete: int
, all are pretty self-explanatory.
Builder methods
These are all fluent methods, so you can chain them together.
table(string $table, string|null $alias)
: if you want to change to another table or didn't set when creating the instancecolumn(string $column, string|null $alias)
: will select all columns if not setwhere
:- you can pass in the whole clause using the first parameter
- or you can pass column, expression and value separately
orderBy(string $column, bool $ascDirection = true)
limit(int $limit, int|null $page)
page(int)
: used to change the offset, only used iflimit
set
Examples
Assuming a \JPI\Database\Query\Builder
instance has been created for the users
database table and set to a variable named $queryBuilder
.
select
This has 4 return types depending on how you use it:
- if you've set
limit
of1
this will return an associative array of key (column) value pairs or if not found thennull
- if paged
\JPI\Database\Query\PaginatedResult
- else
\JPI\Database\Query\Result
PaginatedResult
& Result
work like a normal array just with some extra methods, see https://github.com/jahidulpabelislam/utils?tab=readme-ov-file#collection for more details.
count
As the name implies this method will just return the count as an integer.
For obvious reasons only the table
& where
builder methods are supported for this action.
insert
This method will just return the id of the row created unless it fails then null
.
Only the table
builder method is supported for this action.
update
This method will return the count of how many rows have been updated by the query.
column
& page
builder methods aren't supported for this action.
delete
This method will return the count of how many rows have been deleted by the query.
column
& page
builder methods aren't supported for this action.
Support
If you found this library interesting or useful please spread the word about this library: share on your socials, star on GitHub, etc.
If you find any issues or have any feature requests, you can open an issue or email me @ jahidulpabelislam.com :smirk:.
Authors
Licence
This module is licensed under the General Public Licence - see the licence file for details.