The TableHandler class is designed to facilitate the creation and management of database tables using a PHP object-oriented approach.
It provides methods to define table structures, add columns and foreign keys, create and drop tables, and generate PHP class files
that represent the database tables in a format compatible with the Boostack framework.
$tableHandler = new \Boostack\Models\Database\TableHandler(); $tableHandler->dropTable("offer"); $tableHandler->setTableName("offer"); $tableHandler->addColumn('id', 'INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'); $tableHandler->addColumn('id_customer', 'INT(11) NOT NULL'); $tableHandler->addColumn('id_project', 'INT(11) NULL DEFAULT NULL'); $tableHandler->addColumn('id_product', 'INT(11) NOT NULL'); $tableHandler->addColumn("name", "varchar(255) NOT NULL"); $tableHandler->addColumn("subject", "TEXT NOT NULL"); $tableHandler->addColumn("date", "DATE NOT NULL"); $tableHandler->addColumn("amount", "FLOAT NOT NULL"); $tableHandler->addColumn('created_at', 'TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()'); $tableHandler->addColumn('last_update', 'TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE current_timestamp()'); $tableHandler->addColumn('last_access', 'TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()'); $tableHandler->addColumn('deleted_at', 'TIMESTAMP NULL DEFAULT NULL'); $tableHandler->addIndex("id_customer"); $tableHandler->addIndex("id_project"); #$tableHandler->addForeignKey("id_customer", "gds_customer", "id"); // set up the foreign key sql relations like this #$tableHandler->addForeignKey("id_project", "gds_project", "id"); //set up the foreign key sql relations like this #$tableHandler->addForeignKey("id_product", "gds_product", "id"); //set up the foreign key sql relations like this // Create the table in the database $tableHandler->createTable(); // Generate the PHP class file for the table $className = "ExampleTable"; $tableHandler->generateClassFileFromDatabase($className); // Generate the PHP list class file for the table $tableHandler->generateListClassFile($className);
__construct($objUser = NULL)
void
: No return value.setTableName($tableName)
void
: No return value.addColumn($columnName, $definition)
void
: No return value.addIndex($columnName, $indexType)
void
: No return value.addForeignKey($columnName, $referencedTable, $referencedColumn, $onDelete = 'CASCADE', $onUpdate = 'CASCADE')
void
: No return value.createTable()
void
: No return value.reset()
void
: No return value.dropTable($tableName)
void
: No return value.dropAllTables()
void
: No return value.generateClassFileFromDatabase($className, $namespace = "My\Models")
void
: No return value.generateListClassFile($className, $namespace = "My\Models")
void
: No return value.