I create a system to generate and management a database. The idea is simple: User will be able to define tables, their structures and of course add/edit/remove all data. This dynamic objects should be fully configurated on website level, not in code. Let's assume that I have all necessary information from user (it was send via form) and now I would like to generate new Doctrine object and create table in a database. Is there any way to do this?
Asked
Active
Viewed 228 times
1 Answers
3
Here is what you need:
$sm = $conn->getSchemaManager();
$schema = $sm->createSchema();
$newSchema = clone $schema;
$table = $newSchema->createTable("my_table");
$table->addColumn("id", "integer", array("unsigned" => true));
$table->addColumn("username", "string", array("length" => 32));
$table->setPrimaryKey(array("id"));
$table->addUniqueIndex(array("username"));
$sql = $schema->getMigrateToSql($newSchema, $conn->getDatabasePlatform());
After that just execute your new sql
$conn->exec( $sql );
P.S. conn
is the instance of DBAL connection
. Look here for more info.

Community
- 1
- 1

James Akwuh
- 2,169
- 1
- 23
- 25