rougin / describe
Returns an array of column information from a database table.
Installs: 6 452
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.0
- doctrine/inflector: ~1.0
Requires (Dev)
- phpunit/phpunit: ~4.2
- scrutinizer/ocular: ~1.1
README
Describe is a PHP library that returns Column
objects based on table schema information from a database.
Installation
Install Describe
via Composer:
$ composer require rougin/describe
Basic Usage
Using a vendor-specific driver
use Rougin\Describe\Driver\MySQLDriver; $dsn = 'mysql:host=localhost;dbname=demo'; $pdo = new PDO($dsn, 'root', ''); $driver = new MySQLDriver($pdo, 'demo');
Available drivers:
Using a DatabaseDriver
use Rougin\Describe\Driver\DatabaseDriver; $credentials = array('password' => ''); $credentials['hostname'] = 'localhost'; $credentials['database'] = 'demo'; $credentials['username'] = 'root'; $driver = new DatabaseDriver('mysql', $credentials);
Using Table
$table = new Rougin\Describe\Table('users', $driver); // Returns an array of "Column" instances var_dump($table->columns()); // Returns the primary key "Column" from the table var_dump($table->primary());
For more information regarding the Column
object, kindly check it here.
Adding a new database driver
To add a driver for a specified database, just implement it to a DriverInterface
:
namespace Rougin\Describe\Driver; /** * Database Driver Interface * * An interface for handling PDO drivers. * * @package Describe * @author Rougin Gutib <rougingutib@gmail.com> */ interface DriverInterface { /** * Returns an array of Column instances from a table. * * @param string $table * @return \Rougin\Describe\Column[] */ public function columns($table); /** * Returns an array of Table instances. * * @return \Rougin\Describe\Table[] */ public function tables(); }
Projects using Describe
Combustor
Combustor uses Describe for getting database information for generating a codebase.
Refinery
Same as Combustor, Refinery also uses Describe for creating database migrations for Codeigniter.
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Credits
License
The MIT License (MIT). Please see LICENSE for more information.