PHP code example of dyike / sqltool
1. Go to this page and download the library: Download dyike/sqltool 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/ */
dyike / sqltool example snippets
use Dyike\Sqltool\Sql;
use Dyike\Sqltool\JudgeSql;
$tableOffLine = new Sql('hostOnLine', 'dbName', 'dbUser', 'dbPassword', 'dbPort');
$tableOnLine = new Sql('hostOFFLine', 'dbName', 'dbUser', 'dbPassword', 'dbPort');
//线上的数据表
$tOnLine = $tableOnLine->getTables();
//线下的数据表
$tOffLine = $tableOffLine->getTables();
$judgeSql = new JudgeSql();
//新增的数据
$getTablesToAdd = $judgeSql->getTableToAdd($tOnLine, $tOffLine);
foreach ($getTablesToAdd as $value) {
//获取新增表的创建SQL
$sql = $tableOffLine->getCreateTableSql($value);
print_r($sql);
echo "<br>";
}
foreach ($tOnLine as $value) {
//获取线下表的字段
$fieldsOffLine = $tableOffLine->getFields($value);
//获取线上表的字段
$fieldsOnLine = $tableOnLine->getFields($value);
//新增字段的SQL
$addFieldSql = $judgeSql->toAddFieldSql($fieldsOffLine, $fieldsOnLine, $value);
//修改更新字段的SQL
$updateFieldSql = $judgeSql->toUpdateFields($fieldsOffLine, $fieldsOnLine, $value);
}