2017 © Pedro Peláez
 

library php-database

PHP Database

image

itlessons/php-database

PHP Database

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 5 % Grown

The README.md

PHP Database

Very simple database toolkit for PHP, providing simple pdo wrapper connection and query builder. It currently supports MySQL. Сreated for the study. But you can use it in real projects. Сode taken from Laravel Database Layer and simplified., (*1)

Usage

First, create a new manager instance., (*2)

use Database\Manager;

$manager = new Manager;

$manager->addConnection([
    'dsn' => 'mysql:dbname=testdb;host=127.0.0.1',
    'username' => 'root',
    'password' => null,
    'options' => [] // pdo driver options 
]);

Once the Manager instance has been registered. You may use it like so:, (*3)

Using Connection, (*4)

$conn = $manager->getConnection();
$data = $conn->queryAll('select * from users where id in (?,?,?)', 1, 2, 3);
// $data -> [['id' => 1, 'name' => 'joe'], ...]

$conn->exec('insert into users (id, name) values (?, ?)', 1, 'joe'));

$conn->execBatch(file_get_contents('file_with_queries.txt'));

Using The Query Builder, (*5)

$data = $manager
            ->query('users')
            ->select('*')
            ->whereIn('id', [1,2,3])
            ->execute();

// $data -> [['id' => 1, 'name' => 'joe'], ...]


$data = $manager
            ->query('users')
            ->update(['votes' => 2])
            ->where('id', 1)
            ->toSql();
// $data -> ['update `user` set `votes` = ? where `id` = ?',[2,1]]

$data = $manager
          ->query('users')
          ->insert([
              ['email' => 'john@example.com', 'votes' => 0],
              ['email' => 'john1@example.com', 'votes' => 1]
          ])->execute();

More about query builder see in QueryBuilderTest, (*6)

Installation

The recommended way to install php-database is through Composer. Just create a composer.json file and run the php composer.phar install command to install it:, (*7)

{
    "require": {
        "itlessons/php-database": "*"
    }
}

Alternatively, you can download the php-database.zip file and extract it., (*8)

Resources

You can run the unit tests with the following command:, (*9)

$ cd path/to/php-database/
$ composer.phar install
$ phpunit

The Versions

09/01 2015

dev-master

9999999-dev https://github.com/itlessons/php-database

PHP Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database mysql query builder itlessons

09/01 2015

0.0.1

0.0.1.0 https://github.com/itlessons/php-database

PHP Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database mysql query builder itlessons