1. Go to this page and download the library: Download pinkcrab/table_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/ */
pinkcrab / table_builder example snippets
$schema_a = new Schema('my_table', function(Schema $schema){
// Set columns
$schema->column('id')->unsigned_int(11)->auto_increment();
$schema->column('user')->int(11);
// Set keys and indexes.
$schema->index('id')->primary();
$schema->index('user')->unique();
});
$schema_b = new Schema('my_table');
// Set columns
$schema_b->column('id')->unsigned_int(11)->auto_increment();
$schema_b->column('user')->int(11);
// Set keys and indexes.
$schema_b->index('id')->primary();
$schema_b->index('user')->unique();
$schema_a = new Schema('my_table', function(Schema $schema){
// Set columns
$schema->column('id')->unsigned_int(11)->auto_increment();
$schema->column('user')->int(11);
$schema->column('details')->text();
// Set keys and indexes.
$schema->index('id')->primary();
$schema->index('user')->unique();
$schema->index('details')->full_text();
});
$schema = new Schema('my_table', function(Schema $schema){
// Set columns
$schema->column('id')->unsigned_int(11)->auto_increment();
$schema->column('user')->int(11);
$schema->column('details')->text();
// Set keys and indexes.
$schema->index('id')->primary();
$schema->index('user', 'unique_keys')->unique();
$schema->index('details', 'unique_keys')->unique();
});
$schema = new Schema('my_table', function(Schema $schema){
// Set columns
$schema->column('id')->unsigned_int(11)->auto_increment();
$schema->column('user')->int(11);
$schema->column('details')->text();
// Set keys and indexes.
$schema->index('id')->primary();
$schema->foreign_key('user', 'custom_keyname')
->reference('users', 'id');
});
$schema = new Schema('table', function(Schema $schema): void{
... create schema ...
});
// Create instance of builder with DB Delta engine.
$engine = new DB_Delta_Engine($wpdb);
$builder = new Builder($engine);
// Create table.
try{
// Returns true for success, false for WPDB errors being present.
$response = $builder->create_table($schema);
} catch (\Exception $e) {
// Do something to catch validation errors.
}
$schema = new Schema('table', function(Schema $schema): void{
... create schema ...
});
// Create instance of builder with DB Delta engine.
$engine = new DB_Delta_Engine($wpdb);
$builder = new Builder($engine);
// Create table.
try{
// Returns true for success, false for WPDB errors being present.
$response = $builder->drop_table($schema);
} catch (\Exception $e) {
// Do something to catch validation errors.
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.