I did something similar. But I would not create dynamic classes. I had an object called Schema that would load the data from each table I needed. I had a Table object that would have a Schema type. Each Schema object would have a column attribute, while the Table object had an attribute with a value and a reference to the attribute of the Schema column.
The Scheme was all that you would need to insert, select, delete, update data in the database.
And I had an intermediary that would handle the connection between the database and the Table object.
Table t = new Table('Dog'); t.randomValue(); // needed for the purpose of my project t.save(); Table u = Table.get(t); u.delete();
But it may have something to easily get the value for a specific column name. In any case, the principle is simple, I could load the data contained in the information_data table, which probably could work with the description.
I was able to dynamically load any table, since the table had dynamic attributes, the structure was not hard-coded. But there is no real need to create new classes for each table.
There was also something important that could be noted. Each table schema was loaded once. In tables, only references to schemas and schemas referenced a column. the column had references to the type of column, etc.
It would be interesting to find a better application than it was. I did this for the block case when replicating the database. I had no real interest to code the class for each of the 30 tables and insert / delete / update and select. This is the only reason I can see that it is useful to create something dynamic about sql. If you do not need to know anything about tables and just want to insert / remove garbage into it.
If I had to redo the code, I would use a more associative array.
Anyway, Goodluck
source share