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
Posts: 16
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
richardaslabbert@gmail.com[/color]

Kind Regards
Richard

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 377
Joined: 2018-04-01 10:12

Re: Have a trigger to Auto Create a Database Table

Post by pböttcher » 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.

User avatar
urichard
Posts: 16
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?
richardaslabbert@gmail.com[/color]

Kind Regards
Richard

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 377
Joined: 2018-04-01 10:12

Re: Have a trigger to Auto Create a Database Table

Post by pböttcher » 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.

User avatar
a.gneady
Site Admin
Posts: 992
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: Learn all the tips and tricks of customizing AppGini apps through our online course.

:arrow: Summary Reports plugin enables you to build powerful reports and charts inside your AppGini application through a few simple steps. See the big picture and discover trends in your data that empower you to take the right decisions confidently.

:arrow: Search Page Maker enables you to build user-friendly yet powerful search pages for your AppGini application by simply dragging and dropping the fields you want to include in search.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 114
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

User avatar
urichard
Posts: 16
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
richardaslabbert@gmail.com[/color]

Kind Regards
Richard

Post Reply