PHPackages                             bogdanpet/orthite-db - 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. bogdanpet/orthite-db

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

bogdanpet/orthite-db
====================

PDO wrapper for easier database access

v1.0.3-stable(7y ago)0151MITPHP

Since Aug 1Pushed 7y agoCompare

[ Source](https://github.com/bogdanpet/orthite-db)[ Packagist](https://packagist.org/packages/bogdanpet/orthite-db)[ RSS](/packages/bogdanpet-orthite-db/feed)WikiDiscussions master Synced today

READMEChangelog (3)DependenciesVersions (5)Used By (0)

orthite-db
==========

[](#orthite-db)

PDO Wrapper for easier database access. It is prototype phase and currently only supports mysql. It is possible that some features will work with postgres or sqlite but full support for these drivers will be added later.

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Creating connection](#creating-connection)
    - [Creating connection using dsn, user and password strings](#creating-connection-using-dsn-user-and-password-strings)
    - [Recycling existing PDO connection](#recycling-existing-pdo-connection)
    - [Creating connection using array](#creating-connection-using-array)
    - [Creating child class and configure connection.](#creating-child-class-and-configure-connection)
- [CRUD operations](#crud-operations)
    - [Insert](#insert)
    - [Select](#select)
        - [Limiting results](#limiting-results)
        - [Joining other tables in select](#joining-other-tables-in-select)
        - [Grouping and ordering results](#grouping-and-ordering-results)
    - [Where conditions](#where-conditions)
        - [Other comparisons](#other-comparisons)
    - [Update](#update)
    - [Delete](#delete)
- [Raw queries execution](#raw-queries-execution)
    - [Secure execution of queries](#secure-execution-of-queries)
        - [Custom placeholders with data type specification](#custom-placeholders-with-data-type-specification)
- [Migrations](#migrations)

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

[](#installation)

Install package via composer using command:

```
composer require bogdanpet/orthite-db

```

Creating connection
-------------------

[](#creating-connection)

#### Creating connection using dsn, user and password strings

[](#creating-connection-using-dsn-user-and-password-strings)

Creating connection is the same as creating a new PDO connection using dsn, user and password strings.

```
$db = new \Orthite\Database\Database($dsn, $user, $password)
```

#### Recycling existing PDO connection

[](#recycling-existing-pdo-connection)

If there is already an existing PDO connection it can be passed to Orthite's Database class constructor.

```
$pdo = new \PDO($dsn, $user, $password);

.  .  .

$db = new \Orthite\Database\Database($pdo);
```

#### Creating connection using array

[](#creating-connection-using-array)

Database object can also be made using array containing connection details: driver, host, port, user, password and database.

```
$conn = [
    'driver' => 'mysql',
    'host' => 'localhost',
    'port' => 3306,
    'user' => 'root',
    'password' => 'secret',
    'database' => 'database_name',
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci'
];

$db = new \Orthite\Database\Database($conn);
```

This case is useful when the connection details are stored in some kind of configuration files. Required arguments are database, user and password. Other arguments have default values:

- driver defaults to `mysql`
- host defaults to `localhost`
- port defaults to `3306`
- charset defaults to `utf8`
- collation defaults to `utf8_unicode_ci`

#### Creating child class and configure connection.

[](#creating-child-class-and-configure-connection)

If the same connection is used accross whole application, but database object requires to be set in multiple places it is good to create a child Database class and make connection persistent by overriding the connection property.

```
