PHP code example of czproject / sql-generator

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

    

czproject / sql-generator example snippets


$sql->createTable($tableName);
$sql->dropTable($tableName);
$sql->renameTable($old, $new);
$sql->alterTable($tableName);
$sql->insert($tableName, $data);
$sql->command($command); // for example $sql->command('SET NAMES "utf8"');
$sql->comment($comment);

$sql->addStatement(new Statements\CreateTable($tableName));

$sql->isEmpty();

$sql->toSql($driver); // returns string
$sql->getSqlQueries($driver); // returns string[]
$sql->save($file, $driver); // saves SQL into file

use CzProject\SqlGenerator\TableName;

$table = $sql->createTable(TableName::create('schema.table'))
$table->addForeignKey('fk_table_id', 'id', TableName::create('schema2.table2'), 'id');
// and more ($sql->renameTable(),...)

use CzProject\SqlGenerator\Value;

$table->setOption('AUTO_INCREMENT', Value::create(123)); // generates AUTO_INCREMENT=123
$table->setOption('CHECKSUM', Value::create(FALSE)); // generates CHECKSUM=0
$table->setOption('COMPRESSION', Value::create('NONE')); // generates COMPRESSION='NONE'