PHPackages                             hasirciogli/hdb - 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. hasirciogli/hdb

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

hasirciogli/hdb
===============

Database class like laravel database

1.0.1(2y ago)1331MITPHP

Since Oct 9Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (3)Used By (1)

**README.md for Hasirciogli\\Hdb\\Database Class**

Introduction
------------

[](#introduction)

This README file provides an overview of the `Hasirciogli\Hdb\Database` class, a PHP class designed to simplify database interactions, offering a structure similar to Laravel's database layer.

Features
--------

[](#features)

- **Connection Management:** Establishes a PDO connection to a MySQL database based on configuration provided through an interface (`DatabaseConfigInterface`).
- **Query Building:** Facilitates the construction of SQL queries using a chainable method approach.
- **Prepared Statements:** Employs prepared statements to prevent SQL injection vulnerabilities.
- **Data Binding:** Allows for binding of parameters to queries for dynamic data handling.
- **Execution and Retrieval:** Executes the built query and retrieves results as associative arrays or a single row.

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

[](#installation)

**1. Composer (Recommended):**

If you're using Composer in your project, add the package to your `composer.json` file:

```
"require": {
    "hasirciogli/hdb": "^1.0" // Replace with the specific version you want
}
```

Then, run `composer install` to download the package.

**2. Manual Download:**

Download the `Hasirciogli\Hdb` directory and include it in your project's file structure.

Usage
-----

[](#usage)

**1. Configuration:**

Create a class that implements the `DatabaseConfigInterface`. This interface defines properties for database credentials and connection details:

```
interface DatabaseConfigInterface
{
    const DB_HOST = 'localhost';
    const DB_NAME = 'your_database_name';
    const DB_USER = 'your_username';
    const DB_PASS = 'your_password';
}
```

**2. Database Connection:**

Instantiate the `Database` class, passing an instance of your configuration class:

```
use Hasirciogli\Hdb\Database;
use MyProject\DatabaseConfig; // Replace with your config class path

$db = Database::cfun(new DatabaseConfig());
```

**3. Building Queries:**

Use chainable methods to construct your SQL queries:

```
$users = $db->Select('users')
            ->Where('isActive', true)
            ->OrderBy('username', 'ASC')
            ->Get('all'); // Get all results as an array
```

**4. Prepared Statements and Data Binding:**

The class utilizes prepared statements and data binding automatically. You don't need to manually escape values:

```
$userId = 123;
$user = $db->Select('users')
            ->Where('id', $userId)
            ->Get(); // Get a single user row
```

**5. Additional Methods:**

- `Use(string $DbName)`: Selects a specific database within the connection.
- `LastInsertId()`: Retrieves the last inserted ID after an `INSERT` operation.
- `Insert(string $TableName, $Dataset)`: Builds an `INSERT` query with the specified table name and data.
- `CustomSql(string $Sql)`: Allows for execution of raw SQL queries.

Error Handling
--------------

[](#error-handling)

The `CheckDB()` method throws an exception if a database connection cannot be established. Handle this exception in your code to provide appropriate error messages.

Security Considerations
-----------------------

[](#security-considerations)

While the `Database` class utilizes prepared statements, it's still recommended to validate user input before using it in queries to prevent potential security issues.

Contribution
------------

[](#contribution)

We welcome contributions to improve this library! Fork the repository on GitHub and submit pull requests with your enhancements.

License
-------

[](#license)

This library is licensed under the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

952d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/48149766c33a023f6b1de25fbbda7759798011c69b5329c0e3fa81b68a52ca6f?d=identicon)[hasirciogli](/maintainers/hasirciogli)

---

Top Contributors

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

---

Tags

classdatabasedatabase-classdatabase-managementdatabaselibraydatabselaravellibraryphpphp8php824php83

### Embed Badge

![Health badge](/badges/hasirciogli-hdb/health.svg)

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

###  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)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

PHPackages © 2026

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