Retrieves an array of column information from database

A PHP library that returns column objects based on table schema information from a database.

View source code on Github

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.