5
In my application I have to create a table for each user, tables are created the first time when the user uploads a file and with the name table_$id_user. And the only way I see to create so dynamically is this:
$sql_create_table1 =
"CREATE TABLE IF NOT EXISTS `db`.`table1` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NULL ,
...
PRIMARY KEY (`id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;";
$mysqli->query( $sql_create_table1 );
...
I’ve seen a lot of things over the years and I’ve chosen to do it this way, without having much idea if I’d be doing it the right way.
It’s right to do it this way?
What problems can arise when creating tables like this?
There’s another way to do this?
I was left with many questions about how to program in PHP when reading this answer.
I do not want to go into the basis of the opinion, but rather the basis that the code thus is susceptible to problems?
– Jorge B.
It seems to me that this is a Code Review then. I don’t remember how the status of that is there in [meta]... And it seems to me also that there are 4 questions embedded in one, leaving the question Excessively broad... but I will abstain from voting... many doubts ;)
– brasofilo
I think to answer that I need to ask: what advantages you Do you see the method you use today? Because at first glance it seems simpler to delete PHP and simply run SQL, either in Workbench or another tool. I personally use the command line for this:
mysql --user=root --password=blabla nome_da_base < arquivo.sql
.– bfavaretto