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.
- Host: GitHub
- URL: https://github.com/alexsasharegan/database_lib
- Owner: alexsasharegan
- Created: 2016-08-20T17:36:20.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-02T14:46:52.000Z (about 9 years ago)
- Last Synced: 2025-03-25T03:52:24.676Z (over 1 year ago)
- Topics: database, dbal, mysql, mysql-database, php
- Language: PHP
- Homepage: https://packagist.org/packages/alexsasharegan/database
- Size: 249 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Database
[](https://packagist.org/packages/alexsasharegan/database)
[](https://packagist.org/packages/alexsasharegan/database)
[](https://packagist.org/packages/alexsasharegan/database)
[](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 );
}
```