SQL DDL to PHP code
Really parse CREATE TABLE statements: table name, column names, types, lengths, NULL-ability, defaults, primary keys, AUTO_INCREMENT and COMMENT are all read and mapped to PHP scalar types (int / float / bool / string / array / mixed) plus an array schema, a PHP class or a Doctrine annotated entity. Missing table body or zero columns throws invalid-ddl.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Result
The result can be copied directly.
Paste a CREATE TABLE statement to generate PHP code
Characters: 0 · Columns: 0 · Nullable columns: 0 · Primary keys: 0 · Table: 0
What this tool does
- Turn an existing CREATE TABLE into an entity or array schema.
- Check type and nullability mapping before a migration.
- Generate Doctrine entity skeletons for a project.
Example
Input
CREATE TABLE `users` ( id INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'primary key', name VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'user name', email VARCHAR(128) NULL, PRIMARY KEY (`id`) );
Output
<?php
// 由字段清单生成的表结构描述(表名:users)
return [
'id' => ['type' => 'int', 'sql' => 'int unsigned', 'nullable' => false, 'primaryKey' => true, 'autoIncrement' => true, 'default' => null, 'comment' => 'primary key'],
'name' => ['type' => 'string', 'sql' => 'varchar(64)', 'length' => 64, 'nullable' => false, 'default' => '', 'comment' => 'user name'],
'email' => ['type' => 'string', 'sql' => 'varchar(128)', 'length' => 128, 'nullable' => true, 'default' => null],
];The parser splits column definitions on top-level commas (ignoring commas inside brackets and quotes) and strips inline `--` / `#` comments. Parsing is static and does not connect to a database.
Frequently asked questions
Which SQL dialects are supported?
MySQL / MariaDB syntax is covered best (backticks, AUTO_INCREMENT, COMMENT, UNSIGNED); PostgreSQL / SQLite CREATE TABLE also parses (double-quoted or bracketed identifiers, serial / uuid / text and friends). Unsupported dialect features are ignored rather than guessed.
How do types map to PHP?
Integer family (int / bigint / tinyint / serial) → int; decimal family (decimal / numeric / float / double) → float; bool / boolean / bit → bool; json → array; other string and date types → string; unknown types become mixed.
How are primary keys detected?
Both inline `PRIMARY KEY` and table-level `PRIMARY KEY (...)` are recognised; AUTO_INCREMENT columns count as primary keys, and the Doctrine style adds #[ORM\Id] and #[ORM\GeneratedValue].
What if parsing fails?
When no CREATE TABLE is found or the parentheses contain no column definition, invalid-ddl is thrown and the page shows a clear error instead of partial code.
Keywords:ddl to phpCREATE TABLEdoctrine