PHPackages                             sentience/database - 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. [Database &amp; ORM](/categories/database)
4. /
5. sentience/database

ActiveLibrary[Database &amp; ORM](/categories/database)

sentience/database
==================

The database connector for the Sentience framework

v2.18.2(3w ago)2175↓87.5%1PHPPHP ^8.3

Since Jan 18Pushed 3w agoCompare

[ Source](https://github.com/Sentience-Framework/database)[ Packagist](https://packagist.org/packages/sentience/database)[ RSS](/packages/sentience-database/feed)WikiDiscussions main Synced today

READMEChangelog (10)DependenciesVersions (67)Used By (1)

```
  ____             _   _
 / ___|  ___ _ __ | |_(_) ___ _ __   ___ ___
 \___ \ / _ \ '_ \| __| |/ _ \ '_ \ / __/ _ \
  ___| |  __/ | | | |_| |  __/ | | | |_|  __/
 |____/ \___|_| |_|\__|_|\___|_| |_|\___\___|

 Database

 The lightweight Database Abstraction For Fhe Sentience Framework

 By UniForceMusic

```

The Sentience database abstraction offers a lightweight, no dependencies, database implementation. Through the use of adapter classes it can wrap around PDO, mysqli, and SQLite3. Through the use of easy to extend interfaces it's easy to add your adapters and dialects and use them natively in the Sentience database implementation.

Install the package
===================

[](#install-the-package)

The package requires composer

```
composer require sentience/database

```

### Fully supported database dialects

[](#fully-supported-database-dialects)

- MariaDB (PDO / Mysqli)
- MySQL (PDO / Mysqli)
- Postgres (PDO)
- SQLite (PDO / SQLite3)
- SQL Server (PDO)

### Partially supported database dialects

[](#partially-supported-database-dialects)

- CUBRID (PDO)
- DB2 (PDO)
- Firebird (PDO)
- Informix (PDO)
- Oracle OCI (PDO)

The goal of this database abstraction was to provide an interface that is universally supported across all the implemented database (with currently the only exception being table constraint altering in SQLite). This is achieved by adhering to the SQL standard as much as possible, with a few exception outside the standard such as RETURNING and regexp\_like. For databases that don't natively implement ON CONFLICT or RETURNING clauses, Sentience offers alternatives that emulate the feature.

Sentience database features include:
------------------------------------

[](#sentience-database-features-include)

### Queries

[](#queries)

- SELECT
- INSERT (Native / emulated upsert support for every database)
- UPDATE
- DELETE
- CREATE TABLE
- ALTER TABLE
- DROP TABLE

### Joins

[](#joins)

- LEFT JOIN / INNER JOIN / CROSS JOIN
- Lateral joins (LEFT JOIN LATERAL, INNER JOIN LATERAL, CROSS JOIN LATERAL - SQL Server uses OUTER APPLY / CROSS APPLY)
- Table and SubQuery join variants for each join type

### Where conditions

[](#where-conditions)

- Equals (=) / Not equals (&lt;&gt;)
- IS NULL / IS NOT NULL
- LIKE / NOT LIKE case sensitive (default) and insensitive (SQLITE uses LIKE converted to GLOB)
- GLOB / NOT GLOB (SQLite native, emulated as LIKE conversion for other databases)
- Starts with / Ends with (using LIKE)
- Contains / Not contains (using LIKE)
- IN / NOT IN
- Less than (&lt;) / Less than or equals (&lt;=)
- Greater than (&gt;) / Greater than or equals (&gt;=)
- BETWEEN / NOT BETWEEN
- Empty / Not empty (Mimicking PHP's empty function)
- Regex / Not regex (SQLite also supported using regexp\_like and REGEXP, PostgreSQL uses tilde operators with use\_tilde\_regex option)
- EXISTS / NOT EXISTS (sub query)
- Group / Not group
- Operator
- Raw
- printf-style formatting (wheref, orWheref, havingf, orHavingf with %s, %d, %b, %f modifiers)

### HAVING conditions

[](#having-conditions)

- All where condition variants are available as having\* and orHaving\* methods

### Alter table definitions

[](#alter-table-definitions)

- Add column / Drop column
- Rename column
- Modify column (Not supported in SQLite)
- Add unique constraint (Not supported in SQLite)
- Add foreign key constraint (Not supported in SQLite)
- Drop constraint (Not supported in SQLite)

Why Sentience as your database implementation
=============================================

[](#why-sentience-as-your-database-implementation)

Ever used a database, and suddenly you realize that you're missing a functionality? With Sentience Database, you don't have to worry about that. When a database doesn't support a feature, Sentience does its best to emulate this feature. Such examples are:

- MySQL gets support for returning (with -&gt;lastInsertId('') set)
- SQLite gets support for regular expressions using regexp\_like (Using REGEXP in raw queries is also supported)
- Firebird, OCI, DB2, and SQLServer, get ON CONFLICT resolution support
- Firebird, OCI, DB2, and SQLServer, get IF EXISTS and IF NOT EXISTS support
- PostgreSQL gets DISTINCT ON via -&gt;distinct(\['column'\])
- PostgreSQL 15+ uses regexp\_like() for regex matching (use\_tilde\_regex option enables ~ operator)

Sentience wasn't made to be a drop-in replacement for Eloquent or Doctrine, rather, it attempts to borrow doctrines and best practices from Golang (mainly inspired by the simplicity of [Bun ORM](https://bun.uptrace.dev/)), but with the extra abstractions for where conditions, conflict resolutions, and joins.

1. Getting started
==================

[](#1-getting-started)

To initialize a Sentience database instance, start by initializing your driver from a string:

```
