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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package query

Query

CodeFactor Latest Stable Version Total Downloads Latest Unstable Version License GitHub last commit (branch)

A simple and lightweight SQL query builder library to make querying a database easier. It works as a middleman between your application and the database.

This has been kept very simple stupid (KISS), with minimal validation (PHP type errors only) to reduce complexity in the library and maximize performance for consumer developers. Therefore, please make sure to add your own validation if using user inputs in these queries.

Features

Dependencies

Installation

Use Composer

Usage

To create an instance, you will need an instance of \JPI\Database (which is an extension of PDO - you can find out more 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, insert, update & delete, all are pretty self-explanatory.

Builder methods

These are all fluent methods, so you can chain them together.

table

If you want to change to another table or didn't set when creating the instance.

column

To select a particular column. Call this method multiple times to select multiple columns. This method is also used to add aggregate functions. If not called, all columns will be selected.

join

By default will be a INNER join, use rightJoin or leftJoin methods instead if you want those.

where

Adds an expression to the WHERE clause. This method is very flexible and supports multiple calling patterns:

Note: By default, multiple where() calls on the builder are combined with AND logic. Also note parameters will be keyed by the column, so if you use the same column for 2 different values, it will use the last value added.

Raw expression: Pass a complete expression as the first parameter only

Column, operator, value: Pass column name, operator, and value separately (recommended for security as it uses parameterised queries)

Supported operators: =, !=, <>, <, >, <=, >=, LIKE, IN, NOT IN, BETWEEN

Note: All values (except raw SQL expressions) are automatically parameterised to prevent SQL injection.

IN/NOT IN:

Note: If there is just one value, it will automatically optimise and switch to = or <> operator.

BETWEEN operator: Pass an array with exactly 2 values for the BETWEEN operator

IS NULL / IS NOT NULL: For checking NULL values, use special two-parameter syntax

Subqueries: Pass a Builder instance as the value to use a subquery

orderBy

limit

Add a limit to the query, and optionally set the page at the same time - this sets the OFFSET.

page

Used to change the offset, only used if limit set.

Complex WHERE Conditions

For more complex WHERE clauses that require OR logic or nested conditions, you can use AndCondition and OrCondition classes.

AndCondition

AndCondition groups multiple conditions together with AND logic. Create one using $queryBuilder->newAndCondition().

OrCondition

OrCondition groups multiple conditions together with OR logic. Create one using $queryBuilder->newOrCondition().

Combining AND and OR Conditions

You can nest AndCondition and OrCondition to create complex logic:

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:

PaginatedCollection & Collection work like a normal array just with some extra methods, see https://github.com/jahidulpabelislam/utils?tab=readme-ov-file#collection for more details. Both of these contain multiple instances of Row. PaginatedCollection has meta data on the limit used, page number and total count if not limited, and the collection is immutable.

count

As the name implies this method will just return the count as an integer. By default it will do COUNT(*), but you can pass a column name or expression as the first parameter to count non-NULL values in a specific column or use expressions like DISTINCT.

For obvious reasons only the table, join & where builder methods are supported for this action.

insert

This method supports inserting one or more rows into the table.

Single Row Insert: When inserting a single row successfully, the method returns the last inserted ID, or null if it fails.

Multi-Row Insert: When inserting multiple rows, the method returns the number of rows affected.

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, join & 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, join & 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.


All versions of query with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
jpi/utils Version ^1.0
jpi/database Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jpi/query contains the following files

Loading the files please wait ...