PHP code example of ikkez / f3-schema-builder

1. Go to this page and download the library: Download ikkez/f3-schema-builder 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/ */

    

ikkez / f3-schema-builder example snippets

 php
$db = new \DB\SQL('mysql:host=localhost;port=3306;dbname='.$DBname, $user, $pass);
 php
$schema = new \DB\SQL\Schema( $db );
 php
$generated_queries = $table->build(false);
print_r($generated_queries);
 php
$column = $table->addColumn('deleted');
$column->type($schema::DT_BOOL);
$column->nullable(false);
$column->defaults(0);
$column->after('id');

// or in a fluent way:
$table->addColumn('deleted')->type($schema::DT_BOOL)->nullable(false)->defaults(0)->after('id');
 php
$table->addColumn('title',array(
	'type'=>\DB\SQL\Schema::DT_INT4,
	'nullable'=>false,
	'default'=>'untitled new entry',
	'after'=>'id',
	'index'=>true,
	'unique'=>true,
));
 php
$table->addIndex('name');
 php
$table->addIndex(array('name','email'));
 php
$table->primary('uid');
 php
$table->primary(array('uid','version'));
 php
$table = $schema->createTable('news');
$table->addColumn('title')->type($schema::DT_VARCHAR128);
$table->addColumn('bodytext')->type($schema::DT_TEXT);
$table->addColumn('version')->type($schema::DT_INT8)->nullable(false)->defaults(1);
$table->primary(array('id', 'version'));
$table->build();
 php
$table = $schema->createTable('comments');
$table->setCharset('utf8mb4');
// ...
 php
$table = $schema->alterTable('comments');
$table->setCharset('utf8mb4','general');
// ...
 php
$table->addColumn('creation_date')->type($schema::DT_TIMESTAMP)->defaults($schema::DF_CURRENT_TIMESTAMP);

// a shorthand would be:
$table->addColumn('creation_date')->type_timestamp(TRUE);