err404 / table-creator
创建和初始化 SQL 表
1.0.0
2020-09-18 12:32 UTC
Requires
- vlucas/phpdotenv: ^5.1
This package is auto-updated.
Last update: 2024-09-18 21:41:44 UTC
README
MySQL 基于查询的表生成器。页面加载时创建表。此应用程序使用 PDO 扩展。
使用
- 加载数据库
require_once "DatabaseConnector.php";
所有数据库设置都在 .env 文件中,示例在 index.php 文件中,或[在 GitHub 页面上]{https://github.com/vlucas/phpdotenv}
- 加载创建器
require_once "TableCreator.php";
- 在类中使用
use App\TableCreator; $table = new TableCreator( 'mytable' ); $table->integer('id', 11, '', true ); $table->up();
创建名为 'mytable' 的表 $table = new TableCreator( 'mytable' ); 这将创建一个名为 id 的列,该列将具有整数类型 11 长度,默认值为 '',并作为 AUTO_INCREMENT PRIMARY 键
执行 up() 方法准备好的 SQL。
$table = new TableCreator( 'mytable' ); $table->integer('id', 11, '', true ); $table->string('name' ); $table->string('description' ); $table->up();
(new TableSeeder( 'mytable' ))->seed( $values );
从 values 变量中插入数据到表中。
尝试一下,享受乐趣。没有 3RR-ors