2017 © Pedro Peláez
 

library skeleton-database

Tigron Skeleton Mysql database layer

image

tigron/skeleton-database

Tigron Skeleton Mysql database layer

  • Tuesday, July 31, 2018
  • by tigron
  • Repository
  • 2 Watchers
  • 0 Stars
  • 4,116 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 8 % Grown

The README.md

skeleton-database

Description

This library is a Mysqli wrapper with an easy-to-use API. Most basic features are taken care of automatically., (*1)

Installation

Installation via composer:, (*2)

composer require tigron/skeleton-database

Howto

Create a database connection:, (*3)

$dsn1 = 'mysqli://username:password@localhost/database';
$dsn2 = 'mysqli://username:password@localhost/database2';

$db = \Skeleton\Database\Database::Get($dsn1, true); // The second parameter makes this dsn default
$db = \Skeleton\Database\Database::Get();             // returns a connection to dsn1 as this is default
$db = \Skeleton\Database\Database::Get($dsn2);        // returns a connection to dsn2, don't make it default
$db = \Skeleton\Database\Database::Get();             // returns a connection to dsn1

Get a row of the resultset. The resultset should only contain 1 row, (*4)

$result = $db->get_row('SELECT * FROM user WHERE id=?', [ 1 ]); // Returns one row

Get a column, each element in the array contains the value of a row. The result should only contain 1 row, (*5)

$result = $db->get_column('SELECT id FROM user', []); // Returns 1 column

Get 1 field result., (*6)

$result = $db->get_one('SELECT username FROM user WHERE id=?', [ 1 ]); // Returns 1 field

Get all columns of a give table, (*7)

$result = $db->get_columns('user');

Insert data into a table, (*8)

$data = [
    'username' => 'testuser',
    'firstname' => 'test',
];

$result = $db->insert('user', $data); // Inserts a new row

Update a row, (*9)

$data = [
    'username' => 'testuser',
    'firstname' => 'test',
];

$where = 'id=' . $db->quote(1);
$result = $db->update('user', $data, $where); // Updates a row

Run a query manually, (*10)

$result = $db->query('DELETE FROM `user` WHERE id=?', [ $user_id ]);

Clear all existing database connections, (*11)

Database::Reset();

For debug purpose flags can be set to see the queries, (*12)

\Skeleton\Database\Config::$query_log = false; // (default = false)
\Skeleton\Database\Config::$query_counter = true; // (default = true)

$database = \Skeleton\Database\Database::get();
print_r($database->query_log);
print_r($database->query_counter);

Data quality insurance // Trim data if content is longer than table field \Skeleton\Database\Config::$auto_trim = false; // (default = false), (*13)

// Remove from objects properties which don't exist as table columns
\Skeleton\Database\Config::$auto_discard = false; // (default = false)

// Set to null every column which is not given as input and supports NULL values
\Skeleton\Database\Config::$auto_null = false; // (default = false)

The Versions

31/07 2018

dev-master

9999999-dev

Tigron Skeleton Mysql database layer

  Sources   Download

MIT

The Requires

  • ext-mysqli *

 

by Tigron BVBA

07/06 2017

v0.1.2

0.1.2.0

Tigron Skeleton Mysql database layer

  Sources   Download

MIT

The Requires

  • ext-mysqli *

 

by Tigron BVBA

28/02 2017

v0.1.1

0.1.1.0

Tigron Skeleton Mysql database layer

  Sources   Download

MIT

The Requires

  • ext-mysql *

 

by Tigron BVBA

12/05 2016

v0.1.0

0.1.0.0

Tigron Skeleton Mysql database layer

  Sources   Download

MIT

The Requires

  • ext-mysql *

 

by Tigron BVBA

13/10 2015

v0.0.2

0.0.2.0

Tigron Skeleton Mysql database layer

  Sources   Download

MIT

The Requires

  • ext-mysql *

 

by Tigron BVBA

13/08 2015

v0.0.1

0.0.1.0

Tigron Skeleton Mysql database layer

  Sources   Download

MIT

The Requires

  • ext-mysql *

 

by Tigron BVBA