2017 © Pedro Peláez
 

library database

Database connection handler for IceCream Framework

image

ice-cream/database

Database connection handler for IceCream Framework

  • Friday, March 16, 2018
  • by AdamKyle
  • Repository
  • 0 Watchers
  • 2 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Ice Cream Database

Build Status Packagist Maintenance Made With Love, (*1)

A DBAL at the most simplest of terms. Its a thin wrapper around PDO, while returning a connected PDO object., (*2)

We can connect to multiple database instances of either PGSQL or MYSQL (see below) and create open connections to each., (*3)

  • Requires PHP 7.2.x
  • Is Standalone

Install

composer require ice-cream/database, (*4)

Purpose?

I wanted to understand PDO, and I still have a lot to learn about it. I could have used and created a thin wrapper around Doctrines DBAL, much like I did with Ice Cream Router in the sense that I did a thin wrapper around Symfony's router., (*5)

But I thought I could build something super simple, super easy to get started with and something that allowed me to understand exactly how PHP connects to a database., (*6)

While this isn't as fully flushed out as a regular DBAL, it is a good step in the process. You open a connection, get a db object back, do your work and you move on with your life., (*7)

There is room for growth here and room for improvement and your feedback and help will help to shape Ice Cream components into a framework., (*8)

Documentation

You can see the full documentation for the project here, (*9)

Configuration

Create a new connection instance:, (*10)

use IceCreamDatabase\Connect;

// Similar to that of Laravel if you are familiar.
$connections = [
  'mysql' => [
    'host' => '127.0.0.1',
    'port' => 3306,
    'database' => '',
    'username' => 'root',
    'password' => 'root',
    'charset' => 'utf8',
  ],
  'pgsql' => [
    'host' => '127.0.0.1',
    'port' => 5432,
    'dbname' => 'scotchbox',
    'username' => 'root',
    'password' => 'root',
    'charset' => 'utf8',
  ],
  'sqlite' => [
    'temp_file' => ':memory'
  ]
]

// At this time I have made the choice to only support mysql and pgsql as well as sqlite connections.
// More can be added in the future, simplicity was the game here.

$con = new Connect($connections);

This will throw a PDO exception if we cannot connect to the database. This constructor will also connect to all databases registered in the connection array., (*11)

ATTN!!

At this time the options you see specified in the array are the only ones we accept. I wanted to get this component out the door in a couple of days and decided to keep it as simple as possible for the first iteration., (*12)

So now that we are connected what can we do?, (*13)

$con->db()->exec( ... );

// Should you have multiple databases configured you can do:

$con->db('mysql')->exec( ... );
$con->db('pgsql')->exec( ... );
$con->db('sqlite')->exec( ... );

ATTN!!

Notice in the configuration how we have the key as mysql or pgsql as well as sqlite?, (*14)

This is important because these correlate to the supported drivers that create the connection strings to connect to the database in question., (*15)

These names are also whats stored in the associated connections manager that manages all connections., (*16)

// Get the current connection name:
$con->manager()->getCurrentConnectionName(); // mysql, sqlite or pgsql

The Versions

16/03 2018

dev-master

9999999-dev

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

16/03 2018

1.4.2

1.4.2.0

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

22/01 2017

1.4.1

1.4.1.0

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

21/01 2017

1.4.0

1.4.0.0

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

18/01 2017

1.3.0

1.3.0.0

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

14/01 2017

1.2.1

1.2.1.0

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

14/01 2017

1.2

1.2.0.0

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

14/01 2017

1.1

1.1.0.0

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

12/01 2017

1.0

1.0.0.0

Database connection handler for IceCream Framework

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires