PHPackages                             alexoliverwd/basic-sqlite - 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. alexoliverwd/basic-sqlite

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

alexoliverwd/basic-sqlite
=========================

A simple SQLite helper that makes executing queries easier.

1.0.9(2mo ago)0105↓50%MITPHPPHP &gt;=8.3CI passing

Since Jan 4Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/aoliverwd/basic-sqlite)[ Packagist](https://packagist.org/packages/alexoliverwd/basic-sqlite)[ RSS](/packages/alexoliverwd-basic-sqlite/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (11)Used By (0)

[![PHPUnit](https://github.com/aoliverwd/basic-sqlite/actions/workflows/ci.yml/badge.svg)](https://github.com/aoliverwd/basic-sqlite/actions/workflows/ci.yml/badge.svg) [![Latest Stable Version](https://camo.githubusercontent.com/e5c9ac1c8b180378c3de78863b507317511eb3943e2b01de0c20672fa60414cd/68747470733a2f2f706f7365722e707567782e6f72672f616c65786f6c6976657277642f62617369632d73716c6974652f76)](//packagist.org/packages/alexoliverwd/basic-sqlite) [![License](https://camo.githubusercontent.com/5181e0bf0e60b3990f7b626a8a52edf0eb2830fa34f20087a2a675bc1d4cf9b6/68747470733a2f2f706f7365722e707567782e6f72672f616c65786f6c6976657277642f62617369632d73716c6974652f6c6963656e7365)](https://packagist.org/packages/alexoliverwd/basic-sqlite)

Caution

Please use PHP’s native PDO class instead. This application was an experiment and is no longer actively maintained, except for critical security updates. It remains available only because it is still used by a few legacy applications that are no longer maintained by myself. I may migrate this application to PDO in the future, but for now its use is discouraged.

Basic SQLite
============

[](#basic-sqlite)

Basic SQLite is a lightweight PHP helper class designed to simplify interaction with SQLite databases. It streamlines the process of connecting to, querying, and managing SQLite databases.

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

[](#installation)

Preferred installation is via Composer:

```
composer require alexoliverwd/basic-sqlite
```

Basic Usage
-----------

[](#basic-usage)

The constructor initializes a new instance of the `AOWD\SQLite` class, setting up the connection to the specified SQLite database file. It performs validation to ensure the provided path points to a valid directory and constructs the full path to the SQLite file.

If the parsed directory exists but the specified SQLite file does not, the file will be created automatically.

```
use AOWD\SQLite;

$db_location = __DIR__ . '/example.sqlite';
$db = new SQLite($db_location);
```

When establishing a [new class instance](#__construct), the below methods are available:

- [registerColumn](#registerColumn)
- [beginWriteTransaction](#beginwritetransaction)
- [close](#close)
- [completeWriteTransaction](#completewritetransaction)
- [getColumns](#getcolumns)
- [getCurrentTableName](#getcurrenttablename)
- [getDatabaseLocation](#getdatabaselocation)
- [getIndices](#getindices)
- [getKeyFromName](#getkeyfromname)
- [getNames](#getnames)
- [hasColumn](#hascolumn)
- [migrate](#migrate)
- [query](#query)
- [queryIsWriteStatement](#queryiswritestatement)
- [setTableName](#settablename)

TLDR
----

[](#tldr)

In summary, the example below demonstrates how to use the SQLite helper class to:

1. Set up a database connection.
2. Define a table schema.
3. Insert records using prepared statements.
4. Query the database.
5. Close the connection.

```
// Import the SQLite Helper Class
use AOWD\SQLite;
use AOWD\DataType;

// Create a New SQLite Database Instance
$db = new SQLite(__DIR__ . '/users.sqlite3');

// Set the Target Table
$table = 'users';
$db->setTableName($table);

// Register Columns for the Table
$db->registerColumn('first_name', DataType::TEXT);
$db->registerColumn('last_name', DataType::TEXT);
$db->registerColumn('uuid', DataType::TEXT, false, true, true);

// Create the Table Schema
$db->migrate();

// Insert a Record Using a Prepared Statement
$query = query("SELECT count() AS 'record_count' FROM `$table`");
echo "$count[0][record_count] record(s)";

// Close the Database Connection
$db->close();
```

Public Methods
==============

[](#public-methods)

The below methods are detailed descriptions, parameters, return types, and usage examples for each method.

\_\_construct
-------------

[](#__construct)

### Description

[](#description)

Initializes the SQLite class with a specified database location and optional pragmas.

### Parameters

[](#parameters)

- `$db_location` (string): The file path to the SQLite database.
- `$pragmas` (array): An optional associative array of pragmas to configure the SQLite database.
- `$readonly` (bool) (default: `false`): Specifies whether the database should be opened in read-only mode.

### Pragma Defaults

[](#pragma-defaults)

By default, the following pragmas are set when initializing a new instance:

- journal\_mode: WAL
- busy\_timeout: 5000
- synchronous: NORMAL
- cache\_size: 2000
- temp\_store: memory
- foreign\_keys: true

### Returns

[](#returns)

An instance of the SQLite class.

### Example

[](#example)

```
$db = new SQLite('/path/to/database.sqlite', [
    'cache_size' => 10000
]);
```

registerColumn
--------------

[](#registercolumn)

### Description

[](#description-1)

Is used to define a new column in the database table managed by the `SQLite` class. It supports various column attributes, such as type, nullability, and indexing.

### Parameters

[](#parameters-1)

- `$column_name` (string): The name of the column to be added.
- `$type` (DataType): The data type of the column (e.g., `TEXT`, `INTEGER`).
- `$can_be_null` (bool) (default: `true`): Specifies whether the column can accept `NULL` values.
- `$is_post_required` (bool) (default: `true`): Indicates whether the column must be included in a POST request.
- `$is_index` (bool) (default: `false`): Determines if the column should be indexed for faster lookups.
- `$is_unique` (bool) (default: `false`): Specifies whether the column should enforce unique constraints.

### Return Value

[](#return-value)

This method does not return a value.

### Example Usage

[](#example-usage)

```
// Register a column named 'username' with a TEXT type, non-nullable, and unique constraint
$database->registerColumn(
    column_name: 'username',
    type: DataType::TEXT,
    can_be_null: false,
    is_post_required: true,
    is_index: true,
    is_unique: true
);
```

beginWriteTransaction
---------------------

[](#beginwritetransaction)

### Description

[](#description-2)

Starts a write transaction for the SQLite database.

### Returns

[](#returns-1)

Void.

### Example

[](#example-1)

```
$db->beginWriteTransaction();
```

close
-----

[](#close)

### Description

[](#description-3)

Closes the connection to the SQLite database.

### Returns

[](#returns-2)

Void.

### Example

[](#example-2)

```
$db->close();
```

completeWriteTransaction
------------------------

[](#completewritetransaction)

### Description

[](#description-4)

Completes the current write transaction, committing any changes to the database.

### Returns

[](#returns-3)

Void.

### Example

[](#example-3)

```
$db->completeWriteTransaction();
```

getColumns
----------

[](#getcolumns)

### Description

[](#description-5)

Retrieves a list of column names for the current table.

### Returns

[](#returns-4)

Array of column names.

### Example

[](#example-4)

```
$columns = $db->getColumns();
print_r($columns);
```

getCurrentTableName
-------------------

[](#getcurrenttablename)

### Description

[](#description-6)

Retrieves the name of the current table being operated on.

### Returns

[](#returns-5)

The name of the current table as a string.

### Example

[](#example-5)

```
$table_name = $db->getCurrentTableName();
echo $table_name;
```

getDatabaseLocation
-------------------

[](#getdatabaselocation)

### Description

[](#description-7)

Retrieves the file path of the SQLite database.

### Returns

[](#returns-6)

The database file path as a string.

### Example

[](#example-6)

```
$db_location = $db->getDatabaseLocation();
echo $db_location;
```

getIndices
----------

[](#getindices)

### Description

[](#description-8)

Retrieves a list of indices for the current table.

### Returns

[](#returns-7)

Array of index names.

### Example

[](#example-7)

```
$indices = $db->getIndices();
print_r($indices);
```

getKeyFromName
--------------

[](#getkeyfromname)

### Description

[](#description-9)

Finds the key corresponding to a given name in an array of items.

### Parameters

[](#parameters-2)

- `$items`: An array of items.
- `$name`: The name to find the key for.

### Returns

[](#returns-8)

The key corresponding to the given name.

### Example

[](#example-8)

```
$key = $db->getKeyFromName([['name' => 'users'], ['name' => 'orders']], 'orders');
```

getNames
--------

[](#getnames)

### Description

[](#description-10)

Extracts names from an array of items.

### Parameters

[](#parameters-3)

- `$items`: An array of items to extract names from.

### Returns

[](#returns-9)

Array of names.

### Example

[](#example-9)

```
$names = $db->getNames([['name' => 'users'], ['name' => 'orders']]);
print_r($names);
```

hasColumn
---------

[](#hascolumn)

### Description

[](#description-11)

Checks whether a specified column exists in the current table.

### Parameters

[](#parameters-4)

- `$column_name`: The name of the column to check.

### Returns

[](#returns-10)

Boolean indicating whether the column exists.

### Example

[](#example-10)

```
$has_column = $db->hasColumn('email');
```

migrate
-------

[](#migrate)

### Description

[](#description-12)

Performs migrations to ensure the database schema is up-to-date.

### Returns

[](#returns-11)

Void.

### Example

[](#example-11)

```
$db->migrate();
```

query
-----

[](#query)

### Description

[](#description-13)

Executes an SQL query on the database, with optional parameter binding and row return.

### Parameters

[](#parameters-5)

- `$query`: The SQL query string to execute.
- `$return_rows`: Whether to return rows from the query. Defaults to true.
- `$bind_params`: An associative array of parameters to bind to the query.

### Returns

[](#returns-12)

Array of rows if `$return_rows` is true; otherwise, Void.

### Example

[](#example-12)

```
$rows = $db->query('SELECT  FROM users WHERE id = :id', true, ['id' => 1]);
```

queryIsWriteStatement
---------------------

[](#queryiswritestatement)

### Description

[](#description-14)

Checks if a given query is a write operation (e.g., INSERT, UPDATE, DELETE).

### Parameters

[](#parameters-6)

- `$query`: The SQL query string to analyze.

### Returns

[](#returns-13)

Boolean indicating whether the query is a write operation.

### Example

[](#example-13)

```
$is_write = $db->queryIsWriteStatement('INSERT INTO users (name) VALUES ("John Doe")');
```

setTableName
------------

[](#settablename)

### Description

[](#description-15)

Sets the name of the table to be used for subsequent operations.

### Parameters

[](#parameters-7)

- `$table_name`: The name of the table.

### Returns

[](#returns-14)

Void.

### Example

[](#example-14)

```
$db->setTableName('users');
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance86

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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 ~48 days

Recently: every ~101 days

Total

10

Last Release

66d ago

### Community

Maintainers

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

---

Top Contributors

[![aoliverwd](https://avatars.githubusercontent.com/u/37518812?v=4)](https://github.com/aoliverwd "aoliverwd (29 commits)")

---

Tags

databasesqlite

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alexoliverwd-basic-sqlite/health.svg)

```
[![Health](https://phpackages.com/badges/alexoliverwd-basic-sqlite/health.svg)](https://phpackages.com/packages/alexoliverwd-basic-sqlite)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[catfan/medoo

The lightweight PHP database framework to accelerate development

4.9k1.5M194](/packages/catfan-medoo)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[nette/database

💾 Nette Database: layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.

5656.7M234](/packages/nette-database)[usmanhalalit/pixie

A lightweight, expressive, framework agnostic query builder for PHP.

6872.2M15](/packages/usmanhalalit-pixie)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5013.8M120](/packages/dibi-dibi)

PHPackages © 2026

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