A PHP library that returns column objects based on table schema information from a database.
Describe is a PHP library that returns Column
objects based on table schema information from a database.
Install Describe
via Composer:
$ composer require rougin/describe
use Rougin\Describe\Driver\MySQLDriver;
$dsn = 'mysql:host=localhost;dbname=demo';
$pdo = new PDO($dsn, 'root', '');
$driver = new MySQLDriver($pdo, 'demo');
Available drivers:
DatabaseDriver
use Rougin\Describe\Driver\DatabaseDriver;
$credentials = array('password' => '');
$credentials['hostname'] = 'localhost';
$credentials['database'] = 'demo';
$credentials['username'] = 'root';
$driver = new DatabaseDriver('mysql', $credentials);
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.
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();
}
Combustor uses Describe for getting database information for generating a codebase.
Same as Combustor, Refinery also uses Describe for creating database migrations for Codeigniter.