1. Go to this page and download the library: Download milesasylum/schnoop-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/ */
milesasylum / schnoop-schema example snippets
use MilesAsylum\SchnoopSchema\MySQL\Database\Database;
$database = new Database('schnoop_db');
$database->setDefaultCollation('utf8mb4_general_ci');
$database->setDelimiter('$$');
$database->setDropPolicy(Database::DDL_DROP_POLICY_DROP_IF_EXISTS);
echo $database->getCreateStatement();
/*
DROP DATABASE IF EXISTS `schnoop_db`$$
CREATE DATABASE `schnoop_db` DEFAULT COLLATION 'utf8mb4_general_ci'$$
*/
use MilesAsylum\SchnoopSchema\MySQL\Table\Table;
// Create Table.
$table = new Table('schnoop_tbl');
$table->setEngine(Table::ENGINE_INNODB);
$table->setDefaultCollation('utf8mb4_general_ci');
// ...
use MilesAsylum\SchnoopSchema\MySQL\Column\Column;
use MilesAsylum\SchnoopSchema\MySQL\DataType\IntType;
use MilesAsylum\SchnoopSchema\MySQL\DataType\VarCharType;
use MilesAsylum\SchnoopSchema\MySQL\DataType\TimestampType;
// ...
// Add an ID column.
$idType = new IntType();
$idType->setSigned(false);
$idColumn = new Column('id', $idType);
$idColumn->setAutoIncrement(true);
$idColumn->setNullable(false);
$table->addColumn($idColumn);
// Add a name column.
$nameType = new VarCharType(50);
$nameType->setCollation('ascii_general_ci');
$nameColumn = new Column('name', $nameType);
$table->addColumn($nameColumn);
// Add an updated-at column.
$updatedAtType = new TimestampType();
$updatedAtType->setPrecision(2);
$updatedAtColumn = new Column('updated_at', $updatedAtType);
$updatedAtColumn->setOnUpdateCurrentTimestamp(true);
$updatedAtColumn->setNullable(false);
$table->addColumn($updatedAtColumn);
// ...
use MilesAsylum\SchnoopSchema\MySQL\Constraint\PrimaryKey;
use MilesAsylum\SchnoopSchema\MySQL\Constraint\Index;
use MilesAsylum\SchnoopSchema\MySQL\Constraint\IndexedColumn;
// ...
// Add a primary key
$pkIndex = new PrimaryKey();
$pkIndex->addIndexedColumn(
new IndexedColumn($idColumn->getName())
);
$table->addIndex($pkIndex);
// Add an index on the first 8 characters of the name column.
$nameIndexedColumn = new IndexedColumn($nameColumn->getName());
$nameIndexedColumn->setLength(8);
$nameIndex = new Index('name_idx');
$nameIndex->addIndexedColumn($nameIndexedColumn);
$table->addIndex($nameIndex);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.