A library to abstract the mysql database schema rules
A library to abstract the mysql database schema rules
The installation of this library is made via composer.
Download composer.phar
from their website.
Then add to your composer.json :
"require": {
...
"php-extended/php-db-schema-mysql": "^8"
...
}
Then run php composer.phar update
to install this library.
The autoloading of all classes of this library is made through composer's autoloader.
This library can generate CREATE DATABASE
statements.
use PhpExtended\DbSchema\MysqlTableFactory;
use PhpExtended\DbSchema\MysqlDialect;
use PhpExtended\DbSchema\MysqlTypeNumber;
use PhpExtended\DbSchema\MysqlTypeString;
$factory = new MysqlTableFactory();
$dialect = new MysqlDialect();
$factory->setName('<tableName>');
// <tableColumnId> INT(11) NOT NULL AUTO_INCREMENT COMMENT 'The primary key'
$factory->addColumn('<tableColumnId>', MysqlTypeNumber::INT(), 11, null, null, false, true, 'The primary key');
// <nameColumn> VARCHAR(255) NOT NULL COMMENT 'The name of the <xxx>'
$factory->addColumn('<nameColumn>', MysqlTypeString::VARCHAR(), 255, null, null, false, false, 'The name of the <xxx>');
$factory->addsToPrimaryKey('<tableColumnId>');
$sql = $dialect->showCreateTable($factory->getTable()); // CREATE TABLE ...
MIT (See license file).