2017 © Pedro Peláez
 

library database

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

image

alexsasharegan/database

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  • Sunday, April 2, 2017
  • by alexsasharegan
  • Repository
  • 1 Watchers
  • 2 Stars
  • 79 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 20 Versions
  • 0 % Grown

The README.md

Database

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

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


Installation

With Composer:, (*3)

composer require alexsasharegan/database

Then require in the vendor autoloader:, (*4)

<?php

require_once 'path/to/vendor/autoload.php';

Usage

Static Methods

Calling Database::connect( [ string $configFile = './database.json', array $options = [] ] ) without any arguments will look for a configuration file called database.json file in the calling file's directory. To make use of this default behavior, place your database.json next to your php file. If your config file exists elsewhere, pass in the path as the first argument., (*5)

An example config file is included in the project. Just change the name from database.example.json to database.json and move it next to your calling php file. Here is the example config:, (*6)

<?php

// library defaults
$connectionOptions = [
    'DB_HOST'     => '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:, (*7)

<?php

use Database\MySQL;

# Takes a MySQL-formatted date string and returns a string file path
MySQL::SQLDateToPath( string $SQLDate );
# example
echo MySQL::SQLDateToPath( '2016-09-06 14:02:26' );
# Outputs: '2016/09/06'

# Returns a MySQL-formatted timestamp
echo MySQL::now();
# Outputs: '2016-09-06 14:04:15';

Instance Methods

QUERY

<?php
$mySQL = new \Database\MySQL($connectionOptions, $pdoOptions);

# use a try/catch block to handle a bad query
try {
  $mySQL->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 );
}

The Versions

02/04 2017

dev-master

9999999-dev https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

02/04 2017

2.0.0

2.0.0.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

02/04 2017

dev-v2/PDO

dev-v2/PDO https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

18/11 2016

1.0.16

1.0.16.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

 

by Alex Regan

database sql mysql mysqli rdbms

13/10 2016

1.0.15

1.0.15.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

 

by Alex Regan

database sql mysql mysqli rdbms

13/10 2016

1.0.14

1.0.14.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

 

by Alex Regan

database sql mysql mysqli rdbms

25/09 2016

1.0.13

1.0.13.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

 

by Alex Regan

database sql mysql mysqli rdbms

24/09 2016

1.0.12

1.0.12.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

22/09 2016

1.0.11

1.0.11.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

22/09 2016

1.0.10

1.0.10.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

22/09 2016

1.0.9

1.0.9.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

22/09 2016

1.0.8

1.0.8.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

22/09 2016

1.0.7

1.0.7.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

14/09 2016

1.0.6

1.0.6.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

12/09 2016

1.0.5

1.0.5.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

12/09 2016

1.0.4

1.0.4.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

12/09 2016

1.0.3

1.0.3.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

08/09 2016

1.0.2

1.0.2.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

08/09 2016

1.0.1

1.0.1.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms

06/09 2016

1.0.0

1.0.0.0 https://github.com/alexsasharegan/Database_lib

PHP mysqli utilities to properly handle errors, connections, and make getting data simpler and more DRY.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alex Regan

database sql mysql mysqli rdbms