FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


NEED HELP IN VIEWS AND TRIGGERS





sparks
Does anybody know where to create triggers and how to use then in mysql in order to make simple automated calculations in either mysql or php.
Thanks
MWANGI
I have also been looking for the same thing.I think I pasted a similar question on this forum but cannot seem to find it. Anyways.If I get the answer then I will help you out.
But I think you must have mysql 5 and above to create triggers and views,however I tried to use procedures.I created one but I do not know where to use it or whether to call it in php or mysql.I don't even know how to call it in php.Please help us out here.
We might even donate points.I can see that sparks has 99999999999999FRIH$.I'm sure he/she would'nt mind sharing a few billion with us. lol.

By the way, how did you do that?.Did you hack into the frihost system or what??
sparks
No I did not really hack into the system.I saw that someone else has done a similar thing so I figured out how it was done.
By the way what is a backoffice in php?I was browsing the forum and saw people exchanging php code about backoffices .They seemed so serious and skilled so I felt ashamed to ask them what it is because I might seem ignorant which is a bad label when you are already being called a wannabe by Frihost.
MWANGI
lol

Don't worry about being called a wannabe.It will soon be over after a few more posts but they will call you Junior instead but then later you will be promoted to an adolescent like me.But by then they will be calling me a Frihost freak.It seems nobody has found an answer to your question yet?.They are probably doing some research on it like me or something like that.
poppitz
Hi,

your question covers a topic you can write a lot of pages about.
I will try to give you a short introduction into triggers. I think MWANGI is right and you need mysql 5 for triggers and stored procedures.
A trigger is pl/sql code that you cannot execute on command it is executed when a table is modified.
You define a trigger on a table (if update also on one or more colums of that table).
Further you define the action on which it triggers.
So you can define a trigger for update, one for insert and one for delete and if the trigger should fire before or after the triggering statement.
If you aren't confused yet: There are two different trigger types:
row trigger: is executed for each line which is affected by the triggering statement
statement trigger: is only executed once for each triggering statement.

maybe an example can help:

CREATE OR REPLACE TRIGGER insert_account_for_new_user
AFTER INSERT ON emp
FOR EACH ROW
WHEN (NEW.type <> 'ADMIN')
BEGIN
INSERT INTO Account (name, ...) VALUES (NEW.name, ....)
END;

This trigger would fire on an insert into table emp when the type of the employee who is inserted isn't 'ADMIN'. It fires after the statement was executed and for each line wich is affected by the statement. So if the type is not 'ADMIN', it will insert a record into Account with the name of the new employee. With NEW you can access the values which are inserted by the statement. If it would be an update or delete trigger you could use OLD to access the values which had been stored in the table.

Hope this helps.

There is also some information available at http://dev.mysql.com/doc/refman/5.0/en/triggers.html
rohan2kool
what are triggers in the first place??
MWANGI
Thanks poppitz.That has really helped alot.
By the way
rohan2kool wrote:
what are triggers in the first place??


A trigger is a named database object that is associated with a table and that is activated when a particular event occurs for the table. For example, the following statements create a table and an INSERT trigger. The trigger sums the values inserted into one of the table's columns

They are very new especially in mysql.You must have Sql 5 and above to use them.They are somehow similar to views!.It seems like sql is leaving some of us behind.I also learnt about it just the other day.One month has not yet passed but I am useing them.I would advice anyone who does'nt know them to learn them.Extremely powerful I tell you!!!!
DoctorBeaver
I came across triggers a few years back on a codasyl+ db I was working with but I hadn't heard of them on mySQL until now.

As has been stated, they are very powerful and can save a fair amount of coding when they're used.
Related topics
can i help?
help,Bonding
HELP!!
Help me with MySQL Account Maintenance and phpBB 2.0.15 :((
help, change pass my acc in cpanel
help me upgrade php to 5.
Need help adding a domain
help add admin in phpbb forum
Php and Other Wonderful Newbie Stories for Help.
Michael Moore says...
Cpanel, so many views???!!!! no way!
getting pver someone help!
*still pending please help* trigger support on server 4
Help needed from a volunteer WEB/player DEVELOPER/programmer
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.