PHP code example of atk4 / schema

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

    

atk4 / schema example snippets

 php
$changes = \atk4\schema\Migration::of(new User($app->db))->run();
 php
// create table
$migrator = \atk4\schema\Migration::of($app->db);
$migrator->table('user')
    ->id()
    ->field('name')
    ->field('address', ['type'=>'text']);
    ->create();

// or alter
$migrator = \atk4\schema\Migration::of($app->db);
$migrator->table('user')
    ->newField('age', ['type'=>'integer'])
    ->alter();
 php

// $dbDriver is the connection driver name
// MyCustomMigrator::class should be extending \atk4\schema\Migration

\atk4\schema\Migration::register($platformClass, MyCustomMigrator::class);

 php

$migrator = \atk4\data\schema\Migration::of($connection);
$migrator->table('user')->drop();
$migrator->field('id');
$migrator->field('name', ['type'=>'string']);
$migrator->field('age', ['type'=>'integer']);
$migrator->field('bio');
$migrator->create();
 php

$s = new \atk4\data\schema\Snapshot($connection);
$tables = $s->getDb($tables);

// do anything with tables

$s->setDb($tables);
 php
$q = ['user' => [
    ['name' => 'John', 'surname' => 'Smith'],
    ['name' => 'Steve', 'surname' => 'Jobs'],
]];
$this->setDb($q);

$this->assertEquals($q, $this->getDb('user'));