An open API service indexing awesome lists of open source software.

https://github.com/alexsasharegan/database_lib

A dependency free, light PHP mysqli library to properly handle errors, connections, and make getting data simple and DRY.
https://github.com/alexsasharegan/database_lib

database dbal mysql mysql-database php

Last synced: 6 months ago
JSON representation

A dependency free, light PHP mysqli library to properly handle errors, connections, and make getting data simple and DRY.

Awesome Lists containing this project

README

          

# Database
[![Latest Stable Version](https://poser.pugx.org/alexsasharegan/database/v/stable)](https://packagist.org/packages/alexsasharegan/database)
[![Total Downloads](https://poser.pugx.org/alexsasharegan/database/downloads)](https://packagist.org/packages/alexsasharegan/database)
[![Latest Unstable Version](https://poser.pugx.org/alexsasharegan/database/v/unstable)](https://packagist.org/packages/alexsasharegan/database)
[![License](https://poser.pugx.org/alexsasharegan/database/license)](https://packagist.org/packages/alexsasharegan/database)

PHP MySQL utilities to properly handle errors, connections, and make getting data simple and DRY.

- - - -

## Installation

With **Composer**:

```shell
composer require alexsasharegan/database
```

Then require in the vendor autoloader:
```php
'127.0.0.1',
'DB_NAME' => 'test',
'DB_PORT' => '3306',
'DB_CHARSET' => 'utf8',
'DB_USERNAME' => 'admin',
'DB_PASSWORD' => 'admin',
];

// library defaults
$pdoOptions = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => FALSE,
PDO::ATTR_STRINGIFY_FETCHES => FALSE,
];

$mySQL = new \Database\MySQL($connectionOptions, $pdoOptions);
```

Some other static methods:

```php
select(['firstName', 'lastName'])
->from('users')
->where('id', 'in', [1,2,3])
# we can chain methods together here
->map(
# this can be any callable type ( will be called with each row )
# closures let us 'use' vars from parent scope
# be wary of when you need to pass by reference using &
function ( array $resultRow )
{
$users[] = new User($resultRow); # the $resultRow is an associative array
}
);
} catch ( Exception $e ) {
# insert some custom error handling here
exit( $e );
}
```