Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mySQL Delete Trigger & php

Posted on 2011-09-29
2
Medium Priority
?
509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 80

Accepted Solution

by:
arnold earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

610 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