PHPackages                             geekcow/dbcore - 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. geekcow/dbcore

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

geekcow/dbcore
==============

A basic, simple and lightweight ORM engine for PHP

1.0.41(1y ago)11492Apache-2.0PHPCI failing

Since Aug 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/oleche/dbcore)[ Packagist](https://packagist.org/packages/geekcow/dbcore)[ RSS](/packages/geekcow-dbcore/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (43)Used By (2)

dbcore
======

[](#dbcore)

[![CircleCI](https://camo.githubusercontent.com/a2d991669977035e8f5424adc4cb023aa0e95351fe823a5a8f4560d9aff44725/68747470733a2f2f646c2e636972636c6563692e636f6d2f7374617475732d62616467652f696d672f67682f6f6c656368652f6462636f72652f747265652f6d61737465722e7376673f7374796c653d737667)](https://dl.circleci.com/status-badge/redirect/gh/oleche/dbcore/tree/master) [![Latest Stable Version](https://camo.githubusercontent.com/66ca5e1e25438b5cfe64f8bc4e44861a26d6d0cd426f228d2eae88ce5d7bb2d1/68747470733a2f2f706f7365722e707567782e6f72672f6765656b636f772f6462636f72652f762f737461626c65)](https://packagist.org/packages/geekcow/dbcore) [![Total Downloads](https://camo.githubusercontent.com/f18d9ef4eb2c0e0ac1711e094cfac21ddc47302247120fa6f9969ccb0b4b9bd3/68747470733a2f2f706f7365722e707567782e6f72672f6765656b636f772f6462636f72652f646f776e6c6f616473)](https://packagist.org/packages/geekcow/dbcore)

DBCore Engine Usage Documentation
=================================

[](#dbcore-engine-usage-documentation)

DBCore is a simple, lightweight ORM (Object-Relational Mapping) engine designed for PHP applications. It provides an easy way to interact with databases using PHP objects, abstracting the direct database queries and operations.

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

To use DBCore in your project, you need to install it via Composer. Run the following command in your project directory:

```
composer require geekcow/dbcore
```

Ensure that your project is set up to autoload Composer dependencies. This is usually done by including the Composer-generated `autoload.php` file in your project:

```
require 'vendor/autoload.php';
```

### Configuration

[](#configuration)

DBCore requires a configuration file named `config.ini` in your project directory. This file should contain your database connection settings. A sample configuration might look like this:

```
[database]
host = "localhost"
username = "your_username"
password = "your_password"
dbname = "your_database"
port = 3306
```

Make sure to adjust the settings according to your database server.

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

[](#basic-usage)

### Defining Entities

[](#defining-entities)

Entities in DBCore represent tables in your database. To define an entity, extend the `Entity` class and define your table schema within the class. For example:

```
class User extends Entity {
    private $name_of_the_table = [
        'id' => ['type' => 'int', 'unique' => true, 'pk' => true],
        'username' => ['type' => 'string', 'length' => 32, 'unique' => true],
        'email' => ['type' => 'string', 'length' => 255]
    ];

    public function __construct() {
        parent::__construct($this->name_of_the_table, get_class($this));
    }
}
```

### Performing Database Operations

[](#performing-database-operations)

Once your entity is defined, you can perform various database operations such as fetch, insert, update, and delete.

#### Fetching Data

[](#fetching-data)

To fetch all records:

```
$user = new User();
$result = $user->fetch();
```

To fetch a specific record by ID:

```
$user->fetch_id(['id' => '1']);
```

#### Inserting Data

[](#inserting-data)

To insert a new record:

```
$user = new User();
$user->columns['username'] = 'john_doe';
$user->columns['email'] = 'john@example.com';
$id = $user->insert();
```

#### Updating Data

[](#updating-data)

To update an existing record:

```
$user->fetch_id(['id' => '1']);
$user->columns['email'] = 'new_email@example.com';
$user->update();
```

#### Deleting Data

[](#deleting-data)

To delete a record:

```
$user->fetch_id(['id' => '1']);
$user->delete();
```

Advanced Usage
--------------

[](#advanced-usage)

Query Builders
--------------

[](#query-builders)

DBCore provides a set of query builder classes to simplify the construction of SQL queries. These builders support a fluent interface, allowing you to chain method calls to incrementally build a query.

### QuerySelectBuilder

[](#queryselectbuilder)

The `QuerySelectBuilder` is used to construct SELECT queries. It supports selecting columns, specifying conditions, ordering, and limiting results.

Example usage:

```
