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

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

websitesql/database
===================

The lightweight PHP database framework to accelerate development and reduce complexity.

v1.0.0(1y ago)06MITPHPPHP &gt;=8.0

Since Apr 12Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

WebsiteSQL Database
===================

[](#websitesql-database)

A powerful database wrapper library built on top of [Medoo](https://medoo.in/), providing a simple and intuitive interface for database operations in PHP applications.

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

[](#installation)

```
composer require websitesql/database
```

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

[](#basic-usage)

### Initialization

[](#initialization)

```
// Initialize the database provider
$db = new WebsiteSQL\Database\Database([
    'type' => 'mysql',
    'host' => 'localhost',
    'database' => 'name',
    'username' => 'your_username',
    'password' => 'your_password'
], '../migrations');
```

### CRUD Operations

[](#crud-operations)

#### Select Data

[](#select-data)

```
// Select all records from users table
$users = $db->select("users", "*");

// Select with conditions
$user = $db->get("users", "*", ["id" => 1]);

// Select with JOIN
$data = $db->select("posts", [
    "[>]users" => ["user_id" => "id"]
], [
    "posts.id",
    "posts.title",
    "users.username"
], [
    "posts.status" => "published",
    "ORDER" => ["posts.created" => "DESC"]
]);
```

#### Insert Data

[](#insert-data)

```
$db->insert("users", [
    "username" => "john_doe",
    "email" => "john@example.com",
    "created" => date("Y-m-d H:i:s")
]);

// Get last inserted ID
$lastId = $db->id();
```

#### Update Data

[](#update-data)

```
$db->update("users", [
    "email" => "new_email@example.com"
], [
    "id" => 1
]);
```

#### Delete Data

[](#delete-data)

```
$db->delete("users", [
    "id" => 1
]);
```

### Migrations

[](#migrations)

The database library includes a migration system for managing database schema changes:

```
// Run migrations
$db->migrations()->up();

// Rollback the last batch of migrations
$db->migrations()->down();

// Rollback all migrations
$db->migrations()->reset();

// Refresh migrations (rollback all and run again)
$db->migrations()->refresh();
```

API Reference
-------------

[](#api-reference)

### Base Operations

[](#base-operations)

- `query(string $statement, array $map = [])`: Execute raw SQL queries
- `exec(string $statement)`: Execute raw statement
- `create(string $table, array $columns, array $options = null)`: Create a table
- `drop(string $table)`: Drop a table
- `select(string $table, array $join, array|string $columns = null, array $where = null)`: Select data
- `get(string $table, array $join, array|string $columns = null, array $where = null)`: Get a single record
- `insert(string $table, array $values, string $primaryKey = null)`: Insert data
- `update(string $table, array $data, array $where = null)`: Update data
- `delete(string $table, array $where = null)`: Delete data
- `replace(string $table, array $columns, array $where = null)`: Replace data

### Aggregation

[](#aggregation)

- `count(string $table, array $join = null, string $column = null, array $where = null)`: Count rows
- `avg(string $table, array $join, string $column = null, array $where = null)`: Calculate average
- `max(string $table, array $join, string $column = null, array $where = null)`: Get maximum value
- `min(string $table, array $join, string $column = null, array $where = null)`: Get minimum value
- `sum(string $table, array $join, string $column = null, array $where = null)`: Calculate sum

### Transactions

[](#transactions)

- `action(callable $actions)`: Execute callback in transaction
- `beginTransaction()`: Begin a transaction
- `commit()`: Commit a transaction
- `rollBack()`: Rollback a transaction

### Utilities

[](#utilities)

- `id(?string $name = null)`: Get last inserted ID
- `pdo()`: Get PDO instance
- `debug()`: Get the last query for debugging
- `log()`: Get query log
- `info()`: Get database connection info
- `error()`: Get error information
- `rand(string $table, array $join = null, array|string $columns = null, array $where = null)`: Get random records
- `has(string $table, array $join, array $where = null)`: Check if records exist

### Migrations

[](#migrations-1)

- `migrations()->up()`: Run pending migrations
- `migrations()->down()`: Rollback the last batch of migrations
- `migrations()->reset()`: Rollback all migrations
- `migrations()->refresh()`: Rollback all and run again

License
-------

[](#license)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance46

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

401d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/280e4b985f922abd667a75c49aee0c176202dcbf84464fd50de0cd9328092e60?d=identicon)[alantiller](/maintainers/alantiller)

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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