Describe is a PHP package that returns details of each column based on the database table schema.
Install Describe
via Composer:
$ composer require rougin/describe
use Rougin\Describe\Driver\MysqlDriver;
$dsn = 'mysql:host=localhost;dbname=test';
$pdo = new PDO($dsn, 'root', '');
$driver = new MysqlDriver($pdo, 'test');
Available drivers:
use Rougin\Describe\Driver\DatabaseDriver;
$creds = array('password' => '');
$creds['hostname'] = 'localhost';
$creds['database'] = 'test';
$creds['username'] = 'root';
$driver = new DatabaseDriver('mysql', $creds);
use Rougin\Describe\Table;
$table = new Table('users', $driver);
// Returns a list of columns
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.
To add a driver for a specified database, just implement it to a DriverInterface
:
namespace Rougin\Describe\Driver;
interface DriverInterface
{
/**
* Returns a list of columns from a table.
*
* @param string $table
* @return \Rougin\Describe\Column[]
*/
public function columns($table);
/**
* Returns a list of tables.
*
* @return \Rougin\Describe\Table[]
*/
public function tables();
}
Combustor uses Describe
for getting database information for generating a codebase.
Same as Combustor, Refinery also uses Describe
for creating database migrations for Codeigniter.
Please see CHANGELOG for more information what has changed recently.
$ composer test
The MIT License (MIT). Please see LICENSE for more information.