PHP code example of davajlama / schemabuilder
1. Go to this page and download the library: Download davajlama/schemabuilder library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
davajlama / schemabuilder example snippets
use Davajlama\SchemaBuilder\Bridge\PDOAdapter;
use Davajlama\SchemaBuilder\Driver\MySqlDriver;
use Davajlama\SchemaBuilder\Schema;
use Davajlama\SchemaBuilder\Schema\Type;
use Davajlama\SchemaBuilder\SchemaBuilder;
use Davajlama\SchemaBuilder\SchemaCreator;
$adapter = new PDOAdapter(PDO($dsn, $username));
$driver = new MySqlDriver($adapter);
$builder = new SchemaBuilder($driver);
$schema = new Schema();
$articlesTable = $schema->createTable('articles');
$articlesTable->createId();
$articlesTable->createColumn('title', Type::varcharType(255));
$articlesTable->createColumn('content', Type::textType());
$articlesTable->createColumn('created', Type::dateTimeType());
$articlesTable->createIndex()
->addColumn('created');
$patches = $builder->buildSchemaPatches($schema);
// print queries
foreach($patches as $patch) {
echo $patch->getQuery() . PHP_EOL;
}
// apply patches
$creator = new SchemaCreator($driver);
$creator->applyPatches($patches);