Friday, July 15, 2016

What is a Trigger ???

What is  A trigger ?


Trigger is a Mysql script which evokes on different events

before insert
after insert
before update
after update
before delete
after delete

Trigger Syntax

CREATE TRIGGER triggerName BEFORE/AFTER  INSERT/UPDATE/DELETE ON Table 


Example 

mysql> CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));



mysql> CREATE TRIGGER sumofinsertion  BEFORE INSERT ON account
    -> FOR EACH ROW SET @sum = @sum + NEW.amount;

Now when you insert data in account the trigger evokes

BEFORE INSERT means the trigger will execute before the insert action

Let insert some data


mysql> SET @sum = 0;
mysql> INSERT INTO account VALUES(1,25.05),(2,837.50),(3,-123.00);
mysql> SELECT @sum AS 'Total amount inserted';


+-----------------------+
| Total amount inserted |
+-----------------------+
| 739.55               |
+-----------------------+

Similarly can be set for AFTER and BEFORE of INSERT / UPDATE / DELETE

You can Drop Trigger using syntax


DROP TRIGGER 
sumofinsertion 
;


Thanks

Cheers




Thursday, July 14, 2016

How to set Cron job in CPanelx

How to set  cron job in Cpanel.

First What is a cron job and why it is needed ?

Cron Job is a script that is executed at time as set in server . It is widely used to manipulate the calculation at the end of  period or for bulk emailing ,bulk sms , update database based on some specific conditions.

How to set Cron Job ?

Login to your cpanelx

Search for Cron Jobs


Now you will see this screen



in Cammand line set

you will find setting to configure when will cron job execute.

SYNTAX

php /home/manavpla/public_html/cron.php?method=crontest.php