PHPackages                             minichan-database/minichan-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. minichan-database/minichan-database

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

minichan-database/minichan-database
===================================

A minimal database helper.

127PHP

Since Nov 30Pushed 2y ago2 watchersCompare

[ Source](https://github.com/Leincentes/minichan-database)[ Packagist](https://packagist.org/packages/minichan-database/minichan-database)[ RSS](/packages/minichan-database-minichan-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

DATABASE
========

[](#database)

A minimal PHP database helper for ease development.

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

[](#installation)

```
composer require minichan-database/minichan-database
```

Method Description:
-------------------

[](#method-description)

The `create` method is designed to execute a SQL query for creating a table with the specified name, columns, and optional additional options.

Parameters:
-----------

[](#parameters)

- **$table (string):**The name of the table to be created.
- **$columns (array):**An array representing the columns definition for the new table.
- **$options (array|null):**Additional options for creating the table (optional).

Return Value
------------

[](#return-value)

- If the table creation is successful, the method returns a PDOStatement.
- If the table creation fails, the method returns null.

Usage
-----

[](#usage)

### Example without additional options

[](#example-without-additional-options)

```
$result = create("your_table", [
    "column1" => "INT",
    "column2" => "VARCHAR(255)",
    "column3" => "TEXT"
]);
```

Method Description:
-------------------

[](#method-description-1)

The `query` method is designed to execute a raw SQL statement with optional parameter bindings.

### Parameters:

[](#parameters-1)

- **$statement (string):**The raw SQL statement.
- **$bindings (array):**The array of input parameters value for the prepared statement.

### Return Value:

[](#return-value-1)

If the execution is successful, the method returns a `\PDOStatement`. If the execution fails, the method returns `null`.

### Exceptions:

[](#exceptions)

- Throws `\PDOException` if there is an error in the PDO operation.

### Usage:

[](#usage-1)

```
// without parameter bindings
$result = query("SELECT * FROM your_table");

// with parameter bindings
$result = query("SELECT * FROM your_table WHERE column = ?", ["value"]);
```

Method Description:
-------------------

[](#method-description-2)

The **`select`** method is designed to execute a SELECT query on a specified table, offering flexibility through various parameter combinations.

Parameters:
-----------

[](#parameters-2)

- **$table (string):**The name of the table to query.
- **$columns (array):**An array of columns to be selected.
- **$where (array):**An associative array representing the WHERE conditions for the query.
- **$callback (callable|null):**A callback function that can be applied to each row of the result set (optional).

Return Value:
-------------

[](#return-value-2)

- If no callback is provided:

    - The method returns an array containing the selected rows.
- If a callback is provided:

    - The method returns null.

Usage:
------

[](#usage-2)

```
// without callback
$result = select("your_table", ["column1", "column2"], ["column3" => "value"]);

// with callback
select("your_table", ["column1", "column2"], ["column3" => "value"], function ($row) {
    // custom processing for each row
});
```

Method Description:
-------------------

[](#method-description-3)

The **`insert`** method facilitates the insertion of one or more records into a specified table.

Parameters:
-----------

[](#parameters-3)

- **$table (string):**The name of the table to insert records into.
- **$values (array):**An associative array representing the values to be inserted, where keys are column names.
- **$primaryKey (string|null):**The primary key column name (optional).

Return Value:
-------------

[](#return-value-3)

- The PDOStatement object on success.
- Null on failure.

Usage Example:
--------------

[](#usage-example)

```
// insert
$inserted = insert("your_table", ["column1" => "value1", "column2" => "value2"]);

// with specified primary key
$inserted = insert("your_table", ["column1" => "value1", "column2" => "value2"], "id");
```

Method Description:
-------------------

[](#method-description-4)

The **`update`** method is employed to modify records in a specified table based on the provided conditions.

Parameters:
-----------

[](#parameters-4)

- **$table (string):**The name of the table to update records in.
- **$values (array):**An associative array representing the new values to be set.
- **$where (array):**An associative array representing the WHERE conditions for the update.

Return Value:
-------------

[](#return-value-4)

- The PDOStatement object on success.
- Null on failure.

Usage Example:
--------------

[](#usage-example-1)

```
// update
$updated = update("your_table", ["column1" => "new_value"], ["column2" => "value2"]);

// with specified condition
$updated = update("your_table", ["column1" => "new_value"], ["column2" => "value2", "column3" => "value3"]);
```

Method Description:
-------------------

[](#method-description-5)

The **`delete`** method is utilized to remove records from a specified table based on the provided conditions.

Parameters:
-----------

[](#parameters-5)

- **$table (string):**The name of the table to delete records from.
- **$where (array):**An associative array representing the WHERE conditions for the delete.

Return Value:
-------------

[](#return-value-5)

- The PDOStatement object on success.
- Null on failure.

Usage Example:
--------------

[](#usage-example-2)

```
// delete
$deleted = delete("your_table", ["column1" => "value1"]);

// with specified condition
$deleted = delete("your_table", ["column2" => "value2", "column3" => "value3"]);
```

Method Description:
-------------------

[](#method-description-6)

The **`get`** method is designed to execute a SELECT query and retrieve a single result, which can be either a single row or a single column value.

Parameters:
-----------

[](#parameters-6)

- **$table (string):**The name of the table to query.
- **$columns (array|string):**An array or string representing the columns to be selected.
- **$where (array):**An associative array representing the WHERE conditions for the query.

Return Value:
-------------

[](#return-value-6)

- The result of the SELECT query, which can be a single row or a single column value.

Usage Example:
--------------

[](#usage-example-3)

```
// retrieving a single row
$resultRow = get("your_table", ["column1", "column2"], ["column3" => "value"]);

// retrieving a single column value
$singleValue = get("your_table", "column1", ["column2" => "value2"]);
```

Method Description:
-------------------

[](#method-description-7)

The **`has`** method is employed to determine if records exist in a table based on the provided conditions.

Parameters:
-----------

[](#parameters-7)

- **$table (string):**The name of the table to query.
- **$where (array):**An associative array representing the WHERE conditions for the query.

Return Value:
-------------

[](#return-value-7)

- `true` if records exist based on the conditions.
- `false` otherwise.

Usage Example:
--------------

[](#usage-example-4)

```
// checking if records exist
$hasRecords = has("your_table", ["column1" => "value1"]);

// checking with multiple conditions
$hasRecords = has("your_table", ["column2" => "value2", "column3" => "value3"]);
```

Creation of new instance of Database
====================================

[](#creation-of-new-instance-of-database)

```
$database = new Database([
    'type' => 'mysql',
    'host' => 'localhost',
    'database' => 'db_name',
    'username' => 'db_username',
    'password' => 'db_password'
]);
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![Leincentes](https://avatars.githubusercontent.com/u/70006822?v=4)](https://github.com/Leincentes "Leincentes (12 commits)")

### Embed Badge

![Health badge](/badges/minichan-database-minichan-database/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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