PHPackages                             discite/discite-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. discite/discite-php

ActiveLibrary[API Development](/categories/api)

discite/discite-php
===================

A PHP library for managing MySQL databases in an object-oriented way.

v1.1.0(11mo ago)019MITPHPPHP &gt;=8.1

Since May 14Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/Quintoche/Discite-php)[ Packagist](https://packagist.org/packages/discite/discite-php)[ RSS](/packages/discite-discite-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (11)Used By (0)

Discite-PHP
===========

[](#discite-php)

Discite-PHP is a lightweight and extensible query builder for PHP using MySQLi. It provides an expressive, object-oriented API to manage SQL operations easily.

Discite-PHP helps manipulate, format, correct, and secure SQL queries based on the MySQL manager. The library uses MySQLi.

Several operating modes are available to best suit each use case. The library requires minimal initialization to reduce overhead.

Only the connection must be initialized outside the library for security reasons.

---

Features
--------

[](#features)

- Object-oriented and fluent interface
- Automatic SQL injection protection
- Modular configuration system
- Charset, collation, naming convention, aliasing, prefixing control
- Loose or strict usage modes for tables and keys
- Field (key) declarations with type, index, nullable, default
- Built-in query modifiers and logical operators

---

Summary
-------

[](#summary)

- [Installation](#installation)
- [Usage Example](#usage-example)
- [General Functionality](#general-functionality)
- [Configuration](#configuration)
    - [Load SQL database](#Load-SQL-database)
        - [Load SQL database from file](#Load-SQL-database-from-file)
        - [Load SQL database from database](#Load-SQL-database-from-database)
        - [Retrieve map](#Retrieve-map)
    - [Accessing Configuration](#accessing-the-configuration-interface)
    - [Access to Configuration Constants](#access-to-configuration-variables)
- [General Configuration](#general-configuration)
    - [Charset](#charset)
        - [Available Charsets](#available-charsets)
    - [Collation](#collation)
        - [Available Collations](#available-collations)
    - [Naming Convention](#naming-convention)
        - [Available Naming Conventions](#available-naming-conventions)
    - [Sorting](#sorting)
        - [Available sorting](#available-sorting)
    - [joining](#joining)
        - [Joining methods](#available-methods)
        - [Joining Iterations](#available-iterations)
        - [Joining Separator](#available-separator)
        - [Available joining](#available-joining)
- [Usage Modes](#usage-modes)
    - [Table Usage](#table-usage)
        - [Available Table Usage Modes](#available-table-usage-modes)
    - [Key Usage](#key-usage)
        - [Available Key Usage Modes](#available-key-usage-modes)
- [Keys (Columns)](#keys-columns)
    - [Parameters](#parameters)
    - [Keys Type](#keys-type)
    - [Keys Index](#keys-index)
        - [Column Index](#Column-index)
        - [Table Index](#Table-index)
    - [Nullable](#nullable)
    - [Secure](#secure)
    - [Updatable](#updatable)
    - [Default](#default)
    - [Creating Keys](#creating-keys)
- [Tables](#tables)
    - [Table Parameters](#Table-parameters)
- [Query Operators](#Query-Operators)
    - [All Operator](#All-Operator)
    - [Count Operator](#Count-Operator)
    - [Listing Operator](#Listing-Operator)
    - [Retrieve Operator](#Retrieve-Operator)
    - [Update Operator](#Update-Operator)
    - [Delete Operator](#Delete-Operator)
    - [Create Operator](#Create-Operator)
- [Manipulate Queries](#Manipulate-Queries)
    - [Query Conditions](#Query-Conditions)
        - [Equal Condition](#Equal-Condition)
        - [Or Condition](#Or-Condition)
        - [Contains Condition](#Contains-Condition)
        - [Between Condition](#Between-Condition)
        - [Not Condition](#Not-Condition)
        - [NotIn Condition](#NotIn-Condition)
        - [NotContains Condition](#NotContains-Condition)
        - [Like Condition](#Like-Condition)
        - [NotLike Condition](#NotLike-Condition)
        - [NotBetween Condition](#NotBetween-Condition)
        - [MoreThan Condition](#MoreThan-Condition)
        - [LessThan Condition](#LessThan-Condition)
        - [MoreOrEqual Condition](#MoreOrEqual-Condition)
        - [LessOrEqual Condition](#LessOrEqual-Condition)
    - [Query Modifiers](#Query-Modifiers)
        - [Order Modifier](#Order-Modifier)
        - [Sort Modifier](#Sort-Modifier)
        - [Limit Modifier](#Limit-Modifier)
- [Fetching Results](#Fetching-Results)
    - [Fetching Query](#Fetching-Query)
    - [Fetching All](#Fetching-All)
    - [Fetching Next](#Fetching-Next)
    - [Fetching Array](#Fetching-Array)
    - [Fetching Informations](#Fetching-Informations)
- [Project Structure](#Project-Structure)
- [License](#License)

\--

Installation
------------

[](#installation)

Install with Composer:

```
composer require discite/discite-php
```

---

Usage Example
-------------

[](#usage-example)

This snippet demonstrates how to initialize DisciteDB, configure it, and run a `SELECT` query with condition modifiers:

```
use DisciteDB\Config\Enums\QueryLocation;
use DisciteDB\DisciteDB;
use DisciteDB\Methods\QueryCondition;

ini_set('display_errors','1');
ini_set('display_startup_errors','1');
error_reporting(E_ALL);

require 'default_file.php';

// Define your connection
$_connection = new mysqli('localhost','root','','test_db');

// Snitialize DisciteDB Database
$disciteDB = new \DisciteDB\Database($_connection);

// Set some configurations
  // Charset conf
$disciteDB->configuration()->setCharset(DisciteDB::CHARSET_UTF8MB4);
  // Collation conf
$disciteDB->config()->setCollation(DisciteDB::COLLATION_UTF8MB4_UNICODE_CI);
  // Table usage conf (look at [Usage Modes] for more informations)
$disciteDB->conf()->setTableUsage(DisciteDB::TABLE_USAGE_LOOSE);
  // Key usage conf (look at [Usage Modes] for more informations)
$disciteDB->conf()->setKeyUsage(DisciteDB::KEY_USAGE_LOOSE);

//Here, I decide to list all rows from 'disciteDB_FakeItems'
//That match the following arguments :
  // name is not "White Widget"
  // description start contains "and"
  // price is less or equal "25"
$queryFakeItems = $disciteDB->table('disciteDB_FakeItems')->listing([
    'name'=>QueryCondition::Not('White Widget'),
    'description'=>QueryCondition::Contains('and', DisciteDB::QUERY_LOCATION_BETWEEN),
    'price' => QueryCondition::LessOrEqual(25),
]);

// You can, after that :

// retrieve the SQL Query
echo 'QUERY';
var_dump($queryFakeItems->fetchQuery());

// Retrieve informations (affected rows, time, statut, etc)
echo 'INFORMATIONS ONLY';
var_dump($queryFakeItems->fetchInformations());

// Fetch the next data
  // Is like mysqli_fetch_row || mysqli_result::fetch_row
echo 'NEXT DATA';
var_dump($queryFakeItems->fetchNext());

// Fetch all datas
  // Is like mysqli_fetch_all($result, MYSQLI_ASSOC); || mysqli_result::fetch_all(int $mode = MYSQLI_ASSOC)
echo 'ALL DATA';
var_dump($queryFakeItems->fetchAll());

// Fetch all datas AND informations as an associative array
echo 'ALL DATA AND INFORMATIONS';
var_dump($queryFakeItems->fetchArray());
```

---

General Functionality
---------------------

[](#general-functionality)

To begin using the library, you need a MySQLi connection and to initialize the database manager.

```
// Initialize your connection as usual
$connection = new mysqli('host', 'username', 'password', 'database', 'port');

// Initialize the DisciteDB Manager
$disciteDB = new \DisciteDB\Database($connection);
```

If no connection is provided, the manager will use the following default values:

   Attribute Value    Hostlocalhost Usernameroot Passwordnull Databasedb Portnull ---

Configuration
-------------

[](#configuration)

### Load SQL database

[](#load-sql-database)

if you want to keep `strict` mode (and so, have security, auto-join, etc) available, you can - if you don't want to make manuals definitions - load database directly from a file or the database.

#### Load SQL database from file

[](#load-sql-database-from-file)

```
// Initialize the DisciteDB Manager
$disciteDB = new \DisciteDB\Database($connection);

// Perform loading
$disciteDB->loadFromFile($path, $updatingTime);
```

The library will load tables and columns from a file.

To improve some performances, you can add `$updatingTime` in seconds. If the file is older than the max storage time (`createdTime + $updatingTime`), the library will update the file.

If you want to update the file each time you initialize the library, just set the time to `0`.

#### Load SQL database from database

[](#load-sql-database-from-database)

```
// Initialize the DisciteDB Manager
$disciteDB = new \DisciteDB\Database($connection);

// Perform loading
$disciteDB->loadFromDatabase();
```

The library will load tables and columns directly from database connection.

#### Retrieve map

[](#retrieve-map)

You can retrieve `SQLmap` as an array with a simple method.

```
// Initialize the DisciteDB Manager
$disciteDB = new \DisciteDB\Database($connection);

// Perform loading
$disciteDB->map();
```

### Overview

[](#overview)

You can configure the manager to meet your needs until its destruction.

### Accessing the Configuration Interface

[](#accessing-the-configuration-interface)

With the database manager initiated, access the configuration manager with:

```
$disciteDB->configuration();
```

Aliases:

```
$disciteDB->config();
$disciteDB->conf();
```

### Access to Configuration Variables

[](#access-to-configuration-variables)

To configure the manager without having to import configuration classes, you can call constants via:

```
use DisciteDB\DisciteDB;

// Example usage
DisciteDB::CONST_NAME;
```

---

General Configuration
---------------------

[](#general-configuration)

### Charset

[](#charset)

You can define the charset of the database. By default, the charset used is `utf8mb4`.

```
$disciteDB->config()->setCharset(selected_charset);
```

To retrieve the current charset:

```
$disciteDB->config()->getCharset();
```

#### Available Charsets

[](#available-charsets)

   Constant Value Default?    CHARSET\_UTF8utf8 CHARSET\_UTF8MB4utf8mb4✓ ---

### Collation

[](#collation)

You can define the collation associated with the charset. By default, the collation used is `utf8mb4_unicode_ci`.

```
$disciteDB->config()->setCollation(selected_collation);
```

To retrieve the current collation:

```
$disciteDB->config()->getCollation();
```

#### Available Collations

[](#available-collations)

   Constant Value Default?    COLLATION\_UTF8\_GENERAL\_CIutf8\_general\_ci COLLATION\_UTF8MB4\_BINutf8mb4\_bin COLLATION\_UTF8MB4\_UNICODE\_CIutf8mb4\_unicode\_ci✓ ---

### Naming Convention

[](#naming-convention)

*Can be used only in `strict` mode*

You can define the naming convention to use. The library will automatically change the names and aliases to conform to the selected convention. By default, no convention is selected.

```
$disciteDB->config()->setNamingConvention(selected_naming_convention);
```

To get the current naming convention:

```
$disciteDB->config()->getNamingConvention();
```

#### Available Naming Conventions

[](#available-naming-conventions)

   Constant Value Default?     NAMING\_CONVENTION\_UNDEFINED Undefined ✓   NAMING\_CONVENTION\_CAMEL\_CASE camelCase    NAMING\_CONVENTION\_PASCAL\_CASE PascalCase    NAMING\_CONVENTION\_SNAKE\_CASE snake\_case    NAMING\_CONVENTION\_SNAKE\_UPPERCASE SNAKE\_UPPERCASE   ---

### Sorting

[](#sorting)

You can define if the library automaticly sort the database and if so, from `desc` or `asc`.

By default, the sorting method used is `no_sort`.

```
$disciteDB->config()->setSort(selected_sorting_method);
```

To retrieve the current sorting method:

```
$disciteDB->config()->getSort();
```

#### Available Sorting

[](#available-sorting)

   Constant Value Default?    SORT\_NO\_SORTnull✓ SORT\_DESCDESC SORT\_ASCASC ---

### Joining

[](#joining)

*Can be used only in `strict` mode*

#### Joining Methods

[](#joining-methods)

The Discite-php library allow you to make auto-joining from defined database.

By default, the sorting method used is `no_join`.

```
$disciteDB->config()->setJoinMethod(selected_joining_method);
```

To retrieve the current joining method:

```
$disciteDB->config()->getJoinMethod();
```

#### Joining Iterations

[](#joining-iterations)

You can also set the max occurences of joining the database will throw.

By default, the max interations is set to `0`. No maximum will be used.

You can set joining iterations by :

```
$disciteDB->config()->setJoinMaxIterations(max_interations);
```

To retrieve the current joining method:

```
$disciteDB->config()->getJoinMaxIterations();
```

#### Joining Separator

[](#joining-separator)

You can also set the separator used and retun in `CONCAT` mode.

By default, the separator is set to `, `.

You can set joining separator by :

```
$disciteDB->config()->setJoinSeparator(max_interations);
```

To retrieve the current joining method:

```
$disciteDB->config()->getJoinSeparator();
```

#### Available Joining

[](#available-joining)

   Constant Method Default?    JOIN\_METHOD\_NO\_JOINno joining✓ JOIN\_METHOD\_FLATjoined using INNER RIGHT sql  JOIN\_METHOD\_CONCATjoined using CONCAT sql, return in plain text JOIN\_METHOD\_JSONjoined using JSON\_AGG sql, return in json JOIN\_METHOD\_MULTIDIMENSIONAL\_ARRAYjoined using JSON\_AGG, return in php array ---

Usage Modes
-----------

[](#usage-modes)

The library allows formatting, correction, and adding keys or values to limit errors and reduce tasks.

You can select independently for tables and columns ("keys") either strict or permissive usage modes.

### Table Usage

[](#table-usage)

You can choose strict or permissive usage for tables. Default is strict usage.

```
$disciteDB->config()->setTableUsage(selected_table_usage);
```

To retrieve the current table usage:

```
$disciteDB->config()->getTableUsage();
```

#### Available Table Usage Modes

[](#available-table-usage-modes)

   Constant Value Default?     TABLE\_USAGE\_STRICT Strict usage ✓   TABLE\_USAGE\_LOOSE Loose usage   ---

### Key Usage

[](#key-usage)

You can choose strict or permissive usage for keys (columns). Default is strict usage.

```
$disciteDB->config()->setKeyUsage(selected_key_usage);
```

To retrieve the current key usage:

```
$disciteDB->config()->getKeyUsage();
```

#### Available Key Usage Modes

[](#available-key-usage-modes)

   Constant Value Default?     KEY\_USAGE\_STRICT Strict usage ✓   KEY\_USAGE\_LOOSE Loose usage   ---

Keys (Columns)
--------------

[](#keys-columns)

### Overview

[](#overview-1)

If you are in `loose` usage mode, you may skip this section.

Access key configuration with:

```
$disciteDB->keys();
```

### Parameters

[](#parameters)

A key has several parameters:

ParameterTypeUsageDefaultNullable ?`name``string`Showed name as object```alias``string`Used name in database`$name`✓`prefix``string`Used prefix in database`null`✓`type``DisciteDB::TYPE_[...]`Used in `strict` mode [1](#user-content-fn-1-033be3ae29353f4452f86264d6f177e2)`DisciteDB::TYPE_STRING_STRING`✓`index``DisciteDB::INDEX_TYPE_[...]`Used if you want to set index [2](#user-content-fn-2-033be3ae29353f4452f86264d6f177e2)`DisciteDB::INDEX_TYPE_NONE`✓`indexTable``Table` or `string`Used if you previously set index type`null`✓`default``DisciteDB::DEFAULT_VALUE_[...]` or your own value [3](#user-content-fn-6-033be3ae29353f4452f86264d6f177e2)Used to define default value`DisciteDB::DEFAULT_VALUE_EMPTY_STRING`✓`nullable``bool`Used in `strict` mode. [4](#user-content-fn-3-033be3ae29353f4452f86264d6f177e2)`false`✓`secure``bool`Used in `strict` mode. [5](#user-content-fn-4-033be3ae29353f4452f86264d6f177e2)`false`✓`updatable``bool`Used in `strict` mode. [6](#user-content-fn-5-033be3ae29353f4452f86264d6f177e2)`false`✓### Keys Type

[](#keys-type)

You can select key type. It will be usefull while formatting values. It will escape values which aren't the same as selected type.

Groups are available to help definition :

- `Binary`[7](#user-content-fn-7-033be3ae29353f4452f86264d6f177e2) ;
- `Date`[8](#user-content-fn-8-033be3ae29353f4452f86264d6f177e2) ;
- `String`[9](#user-content-fn-9-033be3ae29353f4452f86264d6f177e2) ;
- `Integer`[10](#user-content-fn-10-033be3ae29353f4452f86264d6f177e2) ;
- `Float`[11](#user-content-fn-11-033be3ae29353f4452f86264d6f177e2) .

*Binary Type*

   Constant Value Size     TYPE\_BINARY\_BLOB blob ✓   TYPE\_BINARY\_TINYBLOB tinyblob    TYPE\_BINARY\_MEDIUMBLOB mediumblob    TYPE\_BINARY\_LONGBLOB longblob    TYPE\_BINARY\_JSON json    TYPE\_BINARY\_FILE file   *Date Type*

   Constant Value Size     TYPE\_DATE\_DATE date ✓   TYPE\_DATE\_TIME time    TYPE\_DATE\_DATETIME datetime    TYPE\_DATE\_TIMESTAMP timestamp    TYPE\_DATE\_YEAR year   *String Type*

   Constant Value Size     TYPE\_STRING\_STRING string ✓   TYPE\_STRING\_SMALLTEXT smalltext    TYPE\_STRING\_MEDIUMTEXT mediumtext    TYPE\_STRING\_LONGTEXT longtext    TYPE\_STRING\_UUID uuid    TYPE\_STRING\_EMAIL email    TYPE\_STRING\_URL url    TYPE\_STRING\_IP ip    TYPE\_STRING\_USERNAME username    TYPE\_STRING\_PASSWORD password   *Integer Type*

   Constant Value Size     TYPE\_INTEGER\_BOOLEAN boolean ✓   TYPE\_INTEGER\_INT int    TYPE\_INTEGER\_BIGINT bigint    TYPE\_INTEGER\_TINYINT tinyint    TYPE\_INTEGER\_MEDIUMINT mediumint    TYPE\_INTEGER\_SMALLINT smallint    TYPE\_INTEGER\_UNIXTIME unixtime   *Float Type*

   Constant Value Size     TYPE\_FLOAT\_FLOAT float ✓   TYPE\_FLOAT\_DOUBLE double    TYPE\_FLOAT\_DECIMAL decimal   ### Keys Index

[](#keys-index)

#### Column Index

[](#column-index)

You can select key index.

Index will be usefull if you decide to make SQL joining method.

ConstUsageDefault ?`DisciteDB::INDEX_TYPE_NONE`null✓`DisciteDB::INDEX_TYPE_INDEX``DisciteDB::INDEX_TYPE_UNIQUE``DisciteDB::INDEX_TYPE_PRIMARY``DisciteDB::INDEX_TYPE_FULLTEXT``DisciteDB::INDEX_TYPE_SPATIAL`#### Table Index

[](#table-index)

You can put a table name as `indexTable`. Usefull to rach joining methods.

### Nullable

[](#nullable)

You can decide if a column can be nullable or not.

### Secure

[](#secure)

In `strict` mode, secured values will not be returning. Such as password.

In the futur, I would like to implement a few new operators such as login who would return only true or false if password match.

### Updatable

[](#updatable)

In `strict` mode, this will disable updatable column value. Would be useful for id.

### Default

[](#default)

You can specify default values. Or you define a string, integer, flaot, etc or you decide to use default pre-defined values.

ConstValue`DisciteDB::DEFAULT_VALUE_NULL``null``DisciteDB::DEFAULT_VALUE_CURRENT_TIMESTAMP``CURRENT_TIMESTAMP()``DisciteDB::DEFAULT_VALUE_ZERO`0`DisciteDB::DEFAULT_VALUE_EMPTY_STRING`` ``DisciteDB::DEFAULT_VALUE_UUIDV4``uuid()``DisciteDB::DEFAULT_VALUE_NOW``CURRENT_TIMESTAMP()`### Creating Keys

[](#creating-keys)

You can create keys in two ways:

```
$disciteDB->keys()->create('key_name', [
  'alias' => 'alias_name',
  'prefix' => 'wanted_prefix',
  'Type' => TYPE_STRING_STRING,
  // etc...
]);
```

or

```
$disciteDB->keys()->add();
```

---

Tables
------

[](#tables)

WIP - documentation

### Overview

[](#overview-2)

If you are in `loose` usage mode, you may skip this section.

Access key configuration with:

```
$disciteDB->tables();
```

### Table Parameters

[](#table-parameters)

A table has several parameters:

ParameterTypeUsageDefaultNullable ?`name``string`Showed name as object```alias``string`Used name in database`$name`✓`prefix``string`Used prefix in database`null`✓`primaryKey``BaseKey`Used to define primary key`null`✓`sort``DisciteDB::SORT_[...]`Used if you want to set a default sorting method`DisciteDB::SORT_NO_SORT`✓---

Query Operators
---------------

[](#query-operators)

You will be able to make queries with multiples operators.

Theses operators are :

- `All`;
- `Count`;
- `Listing`;
- `Retrieve`;
- `Update`;
- `Delete`;
- `Create` *Still not implemented* ;
- `Compare` *Still not implemented* ;
- `Keys` *Still not implemented*;

### All Operator

[](#all-operator)

This operator will return every data in selected table

```
$resultObject = $disciteDb->table('tableName')->all();
```

### Count Operator

[](#count-operator)

This operator will return a count value.

```
$resultObject = $disciteDb->table('tableName')->count($args);
```

You can put filters as arguments. Arguments must be an array. You're able to put flat values, Query Conditions.

```
$args = [
  'columnName' => 'value',
  'columnName' => QueryCondition::Or('value_1', 'value_2');,
];
```

### Listing Operator

[](#listing-operator)

This operator will return a values based on filters. It's like `all` operator with arguments.

```
$resultObject = $disciteDb->table('tableName')->listing($args);
```

You can put filters as arguments. Arguments must be an array. You're able to put flat values, Query Conditions or Query modifiers.

```
$args = [
  'columnName' => 'value',
  'columnName' => QueryCondition::Or('value_1', 'value_2');,
  QueryModifier::Sort(DisciteDB::SORT_DESC, 'id');
];
```

### Retrieve Operator

[](#retrieve-operator)

This operator will be used to retrieve single data.

```
$resultObject = $disciteDb->table('tableName')->retrieve($uuid);
```

UUID can be a `string`, an `integer` or an `array`. For the two first, in `strict` mode, primary indexed key will be used as id. If you want to manually specify uuid key name, you must set UUID as an array.

```
// String or integer definition
$uuid = 3;

// Array definition
$uuid = [
  'columnName' => 'value',
];
```

---

### Update Operator

[](#update-operator)

This operator will be used to update data.

```
$resultObject = $disciteDb->table('tableName')->update($uuid, $args);
```

UUID can be a `string`, an `integer` or an `array`. For the two first, in `strict` mode, primary indexed key will be used as id. If you want to manually specify uuid key name, you must set UUID as an array.

```
// String or integer definition
$uuid = 3;

// Array definition
$uuid = [
  'columnName' => 'value',
];
```

You must put values as arguments. Arguments must be an array. You're able to put flat values only.

```
$args = [
  'columnName' => 'value',
];
```

---

### Delete Operator

[](#delete-operator)

This operator will be used to delete data.

```
$resultObject = $disciteDb->table('tableName')->delete($uuid);
```

UUID can be a `string`, an `integer` or an `array`. For the two first, in `strict` mode, primary indexed key will be used as id. If you want to manually specify uuid key name, you must set UUID as an array.

```
// String or integer definition
$uuid = 3;

// Array definition
$uuid = [
  'columnName' => 'value',
];
```

---

### Create Operator

[](#create-operator)

This operator will be used to create data.

In `strict` mode, undefined values will be generate by the library with default previously defined values.

```
$resultObject = $disciteDb->table('tableName')->create($args);
```

You must put values as arguments. Arguments must be an array. You're able to put flat values only.

```
$args = [
  'columnName' => 'value',
];
```

---

Manipulate Queries
------------------

[](#manipulate-queries)

You are able to manipulate queries. At this time, with previously showed `$args`. You would just set an `equal` condition and default sorting/limit.

With theses user-friendly queries "manipulators", you'll see that is easy to perform a strong query.

### Query Conditions

[](#query-conditions)

Theses methods, used in `listing` and `count`, will auto-format (even in loose usage mode) query based on parameters you give.

#### Equal Condition

[](#equal-condition)

Simple Condition. Must not be used because you can perform this condition with a standard argument.

```
QueryCondition::Equal('value');
```

#### Or condition

[](#or-condition)

You can put every values as you want to check.

```
QueryCondition::Or('value_1','value_2');
```

Library will format like this :

```
('columnName' = 'value_1' OR 'columnName' = 'value_2')
```

#### Contains condition

[](#contains-condition)

You must send location. Default used const is `QUERY_LOCATION_BETWEEN`.

```
QueryCondition::Contains('value', DisciteDB::QUERY_LOCATION_[...]);
```

Library will format like this :

```
'columnName' LIKE '%value%'
```

Location will format value as :

ConstValue format`DisciteDB::QUERY_LOCATION_STARTWITH``%value``DisciteDB::QUERY_LOCATION_ENDWITH``value%``DisciteDB::QUERY_LOCATION_BETWEEN``%value%`#### Between condition

[](#between-condition)

You can put every values as you want to check.

```
QueryCondition::Between(10, 20);
```

Library will format like this :

```
'columnName' BETWEEN 10 AND 20
```

#### Not condition

[](#not-condition)

```
QueryCondition::Not('value');
```

Library will format like this :

```
'columnName' != 'value'
```

if you specify more than one argument. `NotIn` condition will replace `Not` condition automaticly.

#### NotIn condition

[](#notin-condition)

```
QueryCondition::NotIn('value_1','value_2');
```

Library will format like this :

```
'columnName' NOT IN ('value_1', 'value_2')
```

if you specify only one argument. `Not` condition will replace `NotIn` condition automaticly.

#### NotContains condition

[](#notcontains-condition)

You must send location. Default used const is `QUERY_LOCATION_BETWEEN`.

```
QueryCondition::NotContains('value', DisciteDB::QUERY_LOCATION_[...]);
```

Library will format like this :

```
'columnName' NOT LIKE '%value%'
```

Location will format value as :

ConstValue format`DisciteDB::QUERY_LOCATION_STARTWITH``%value``DisciteDB::QUERY_LOCATION_ENDWITH``value%``DisciteDB::QUERY_LOCATION_BETWEEN``%value%`#### Like condition

[](#like-condition)

You must send location. Default used const is `QUERY_LOCATION_BETWEEN`.

```
QueryCondition::Like('value', DisciteDB::QUERY_LOCATION_[...]);
```

Library will format like this :

```
'columnName' LIKE '%value%'
```

Location will format value as :

ConstValue format`DisciteDB::QUERY_LOCATION_STARTWITH``%value``DisciteDB::QUERY_LOCATION_ENDWITH``value%``DisciteDB::QUERY_LOCATION_BETWEEN``%value%`#### NotLike condition

[](#notlike-condition)

Aliase of `NotContains`.

#### NotBetween condition

[](#notbetween-condition)

```
QueryCondition::NotBetween(10, 20);
```

Library will format like this :

```
'columnName' NOT BETWEEN 10 AND 20
```

#### MoreThan condition

[](#morethan-condition)

```
QueryCondition::MoreThan(10);
```

Library will format like this :

```
'columnName' > 10
```

#### LessThan condition

[](#lessthan-condition)

```
QueryCondition::LessThan(10);
```

Library will format like this :

```
'columnName' = 10
```

#### LessOrEqual condition

[](#lessorequal-condition)

```
QueryCondition::LessOrEqual(10);
```

Library will format like this :

```
'columnName' table('disciteDB_FakeItems')->all();

// Fetching all datas for example.
print_r($result->fetchAll());
```

Result will be :

```
array(12) {
    [0]=>
  array(6) {
    ["id"]=>
    int(2)
    ["category_id"]=>
    int(1)
    ["name"]=>
    string(10) "Red Widget"
    ["description"]=>
    string(29) "A slightly larger red widget."
    ["price"]=>
    float(15.4900000000000002131628207280300557613372802734375)
    ["created_at"]=>
    string(19) "2025-06-04 19:45:27"
  }
  [1]=>
  array(6) {
    ["id"]=>
    int(3)
    ["category_id"]=>
    int(1)
    ["name"]=>
    string(12) "Green Widget"
    ["description"]=>
    string(23) "A stylish green widget."
    ["price"]=>
    float(13.75)
    ["created_at"]=>
    string(19) "2025-06-04 19:45:27"
  }
  // .........
  }
```

### Fetching Next

[](#fetching-next)

You'll retrieve the next result as `array`.

Doing this will make the same result as : `mysqli_fetch_row($result)` or `mysqli_result::fetch_row()`.

Informations will be also returned.

```
$result = $disciteDB->table('disciteDB_FakeItems')->all();

// Fetching next data for example.
print_r($result->fetchNext());
```

Result will be :

```
array(2) {
  ["data"]=>
  array(6) {
    ["id"]=>
    int(1)
    ["category_id"]=>
    int(1)
    ["name"]=>
    string(11) "Blue Widget"
    ["description"]=>
    string(32) "A small blue widget for testing."
    ["price"]=>
    float(10.9900000000000002131628207280300557613372802734375)
    ["created_at"]=>
    string(19) "2025-06-04 19:45:27"
  }
  ["info"]=>
  array(4) {
    ["status"]=>
    string(7) "success"
    ["time"]=>
    int(1749059127)
    ["query"]=>
    array(5) {
      ["operator"]=>
      string(3) "All"
      ["table"]=>
      string(19) "disciteDB_FakeItems"
      ["context"]=>
      NULL
      ["gaveArgments"]=>
      int(0)
      ["affectedRows"]=>
      int(12)
    }
    ["error"]=>
    NULL
  }
}
```

### Fetching Array

[](#fetching-array)

You'll retrieve all datas as `array`.

Doing this will make the same result as : `mysqli_fetch_all($result, MYSQLI_ASSOC)` or `mysqli_result::fetch_all(int $mode = MYSQLI_ASSOC)`.

Informations will be also returned.

```
$result = $disciteDB->table('disciteDB_FakeItems')->all();

// Fetching array datas for example.
print_r($result->fetchArray());
```

Result will be :

```
array(2) {
  ["data"]=>
  array(12) {
    // Datas
  }
  ["info"]=>
  array(4) {
    ["status"]=>
    string(7) "success"
    ["time"]=>
    int(1749059127)
    ["query"]=>
    array(5) {
      ["operator"]=>
      string(3) "All"
      ["table"]=>
      string(19) "disciteDB_FakeItems"
      ["context"]=>
      NULL
      ["gaveArgments"]=>
      int(0)
      ["affectedRows"]=>
      int(12)
    }
    ["error"]=>
    NULL
  }
}
```

### Fetching Informations

[](#fetching-informations)

You'll retrieve informations only as `array`.

```
$result = $disciteDB->table('disciteDB_FakeItems')->all();

// Fetching informations for example.
print_r($result->fetchInformations());
```

Result will be :

```
array(4) {
  ["status"]=>
  string(7) "success"
  ["time"]=>
  int(1749059127)
  ["query"]=>
  array(5) {
    ["operator"]=>
    string(3) "All"
    ["table"]=>
    string(19) "disciteDB_FakeItems"
    ["context"]=>
    NULL
    ["gaveArgments"]=>
    int(0)
    ["affectedRows"]=>
    int(12)
  }
  ["error"]=>
  NULL
}
```

---

Project Structure
-----------------

[](#project-structure)

- `src/` – Core library files
- `example/` – Usage demonstrations
- `tests/` – PHPUnit testing

License
-------

[](#license)

MIT License — see `LICENSE` file.

Created by Romain QUINTAINE.

Footnotes
---------

1. [↩](#user-content-fnref-1-033be3ae29353f4452f86264d6f177e2)
2. [↩](#user-content-fnref-2-033be3ae29353f4452f86264d6f177e2)
3. [↩](#user-content-fnref-6-033be3ae29353f4452f86264d6f177e2)
4. [↩](#user-content-fnref-3-033be3ae29353f4452f86264d6f177e2)
5. [↩](#user-content-fnref-4-033be3ae29353f4452f86264d6f177e2)
6. [↩](#user-content-fnref-5-033be3ae29353f4452f86264d6f177e2)
7. [↩](#user-content-fnref-7-033be3ae29353f4452f86264d6f177e2)
8. [↩](#user-content-fnref-8-033be3ae29353f4452f86264d6f177e2)
9. [↩](#user-content-fnref-9-033be3ae29353f4452f86264d6f177e2)
10. [↩](#user-content-fnref-10-033be3ae29353f4452f86264d6f177e2)
11. [↩](#user-content-fnref-11-033be3ae29353f4452f86264d6f177e2)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance53

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

10

Last Release

306d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bf9799b3fc6259034e5fb370ce967ffbb8d117c8d494f59a21c0bd156f90fca8?d=identicon)[quintoche](/maintainers/quintoche)

---

Top Contributors

[![Quintoche](https://avatars.githubusercontent.com/u/92650379?v=4)](https://github.com/Quintoche "Quintoche (30 commits)")

---

Tags

apimanagermysqlmysqliphpphp8query-builderquery-formatting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/discite-discite-php/health.svg)

```
[![Health](https://phpackages.com/badges/discite-discite-php/health.svg)](https://phpackages.com/packages/discite-discite-php)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
