Have a trigger to Auto Create a Database Table

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Have a trigger to Auto Create a Database Table

Post by urichard » 2018-11-21 21:30

Hi Please help

I know it might not be suggested to have a separate table for each client that uses my database but i have my reasons why i want to create each of them their own database, i just don't want to create it after every time a new member signs up but instead hoped that after i generated my application after i have already designed all the tables and fields to have a trigger in the application that whenever a new client subscribes or registers with my application that there should automatically be a new database table created for that member to have all their records separate from other member's records, hopefully some code in the hooks folder i guess to auto create a additional new database table with fields pre-designed

Please help
Kind Regards
Richard
[email protected][/color]

Kind Regards
Richard

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Have a trigger to Auto Create a Database Table

Post by pbottcher » 2018-11-22 06:33

Hi,

just to understand. If you create a table for each new user (programatically), how would you access these tables through your application.
AppGini would not know about those tables.

As a suggestion: you could check if the table already exists in the database for the currently logged in user, and if not, create it.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Re: Have a trigger to Auto Create a Database Table

Post by urichard » 2018-11-22 09:02

Hi pbottcher

Thanks again for the quick response.

Wouldn't appgini know in a way of setting a if statement in some php code like for example as you said above.. to programatically create the new table once a user has registered and then when that user wants to access their own records table with zero records in or with records generated or "viewed" as with your previous post answer(which doesn't exist yet) to then auto create the table and tell appgine how to access this table for that user?

If this is possible? And what code would i need?
[email protected][/color]

Kind Regards
Richard

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Have a trigger to Auto Create a Database Table

Post by pbottcher » 2018-11-22 10:43

Hi,

I think this is not possible with the nature of AppGini. AppGini uses either an exisiting database and you specify through the GUI how the behaviour for the fields should be (e.g. lookup-field, or download, etc). Or you create your tables and fields through AppGini and once done you will create your application (app). This will generate the code that will handle those tables/fields.

If you add additional tables/fields now through the database directly (or even programaticaly through code in you app) AppGini would not know about those tables/fields and hence you would not have a web page to access your newly created tables/fields.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Have a trigger to Auto Create a Database Table

Post by a.gneady » 2018-11-28 11:11

Hmm ... I guess it could be done if some naming rules are followed. I didn't analyze it in full detail but I can imagine it might work as follows: let's say a new member signs up. In the member_activity hook, you create a new table named for example "profile_{$username}" (so that the username is part of the table.

Before that, you should have defined a "profile" table in AppGini so that AppGini creates the interface files for it (profile_view.php, ... etc). And profile_username table that you create in the member_activity hook should follow the same schema ... Next, in the hooks/profile.php file, set the tablename in the profile_init hook to 'profile_{$userame}' .. you'd also need to set some other properties of the $options object in that init hook like $options->QueryFieldsTV, $options->QueryFieldsCSV, ... etc.

The above would cause AppGini to show data stored in the user-specific table rather than the generic profile table when the user visits profile_view.php ... Again, I didn't analyze this in detail or test it, but you could give it a try.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Have a trigger to Auto Create a Database Table

Post by jsetzer » 2018-11-28 12:00

Next, in the hooks/profile.php file, set the tablename in the profile_init hook to 'profile_{$userame}' .. you'd also need to set some other properties of the $options object in that init hook like $options->QueryFieldsTV, $options->QueryFieldsCSV, ... etc.
Nice and interesting idea, @Ahmad !
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Re: Have a trigger to Auto Create a Database Table

Post by urichard » 2018-12-11 23:17

Awesome!!!

I will give it a try and let you know how it works thanks a.gneady

Regards
Richard
[email protected][/color]

Kind Regards
Richard

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Have a trigger to Auto Create a Database Table

Post by bruceholt » 2019-06-09 00:09

Has anyone managed to work out how to do this as I, and probably many others would like to do it. The problem with only one big table I think, is that if there is an issue with the database, you could potentially loose everything.

Post Reply