Solved

mySQL Delete Trigger & php

Posted on 2011-09-29
2
484 Views
Last Modified: 2012-06-27
I want to create a delete trigger that will run before a record gets deleted, however I would like to get some external data passed to this trigger and have no idea how to do this or even if it can be done.

The delete trigger will take the record about to be deleted and paste it into another table, but I also want it to take the username from php - value of $_SESSION['login_user'] which holds the username value of whoever is logged into the app and is trying to delete the record.

Since the Trigger is in the database and not in the php code, how do i get this info to it??
0
Comment
Question by:saunaG
2 Comments
 
LVL 24

Expert Comment

by:johanntagle
ID: 36818295
I don't think MySQL triggers have that capability.  It can only use data from the table involved and (I think) from the MySQL session.  Suggest you do the copying to another table in your php code.  OR, still make the trigger, then have the php code update the row in the other after it calls the delete.  This was you will always copy the row to the other table, whether the delete is called by php or not.
0
 
LVL 76

Accepted Solution

by:
arnold earned 500 total points
ID: 36864864
Which version of mysql are you using?
http://dev.mysql.com/doc/refman/5.5/en/triggers.html
This thread might be what you are looking for
http://forums.mysql.com/read.php?99,140057,140057
The last post seems to be the example you are looking for
http://forums.mysql.com/read.php?99,140057,141249#msg-141249

The last part dealing with the take value, is not possible.

You should create a log table which will record transactions performed on the site at which point you could update/record which records were affected.
i.e. instead of actually deleting records, you could tag the record as delete using a deleted column and then reference who issued the delete. You would then have a cleanup process that will go through the table looking for rows marked for deletion and perform the transaction you want i.e. get the row into another table with the reference to the user that deleted it.

I think this approach gets to the point you want to achieve.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now