rougin/describe

Get the information about the database you're working on in PHP

v1.6.0 2017-01-05 07:37 UTC

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Gets information of a table schema from a database in PHP.

Install

Via Composer

$ composer require rougin/describe

Usage

$pdo    = new PDO('mysql:host=localhost;dbname=demo', 'root', '');
$driver = new Rougin\Describe\Driver\MySQLDriver($pdo, 'demo');

// or

$credentials = [ 'hostname' => 'localhost', 'database' => 'demo', 'username' => 'root', 'password' => '' ];
$driver      = new Rougin\Describe\Driver\DatabaseDriver('mysql', $credentials);

$describe = new Rougin\Describe\Describe($driver);

// Returns an array of "Column" objects from the specified table
var_dump($describe->getColumns('users'));
var_dump($describe->getTable('users'));

// Returns an array of available tables from the database
var_dump($describe->showTables());
var_dump($describe->getTableNames());

// Gets the primary key from the specified table
// Second parameter means to return the "Column" object or the column name
var_dump($describe->getPrimaryKey('users', true));

For more information regarding the Column object, you can check it here.

Adding a new database driver

You can always add a new database driver if you want. Just implement the database driver of your choice in a DriverInterface.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email rougingutib@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.