Friday, March 4, 2011

Thank You Words For Engagement Words

Trigger mysql - php


The trigger or triggers are objects that are used in the database only, are executed before or after certain actions: insert, delete or update.


There are certain rules that we must not forget:

  • The trigger works fine (until now) just for a table.
  • The trigger does not work for views or temporary tables.
  • The trigger does not work when executing cascade; do update on TableA and this in turn update on TableB ago TableB use a trigger if this is not self-executing.
  • All trigger must be removed before upgrading mysql version (at least version 5 to 5.0).
  • can not make two corresponding trigger and instruction at the same time, you can not have insert after twice to the same table.

Example of a trigger:



   mysql>   CREATE TABLE my_table (variable INT, amount DECIMAL (10,2));   
     mysql> CREATE TRIGGER  name: trigger BEFORE INSERT ON my_table  
    -> FOR EACH ROW SET @ var = @ var + NEW.var2;  





OLD and NEW: used to refer to the contents of the variable depending on its condition, the sample is the value again ... (maybe because it says New?).


To run a trigger from php, you can not, so if you can do is run a stored procedure and :


mysqli_query $ run = ("mi_procedimiento ($ parameter1, $ parameter2));


Example stored procedure:



mi_procedimiento CREATE PROCEDURE (IN parameter1 INTEGER)
     BEGIN
            DECLARE var1 CHAR(10);
            IF parametro1 = 17 THEN
                    SET var1 = 'birds';
            ELSE
                    SET var1 = 'beasts';
            END IF;
INSERT INTO table1 VALUES (var1);
END




More information:



I hope I have helped a little, any correction is welcome characteristics can see trigger and stored procedures here or find i nformation official: dev. mysql.com

0 comments:

Post a Comment