Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:19:43+00:00 2026-06-08T10:19:43+00:00

I have been working with a small team on a small project about fiction

  • 0

I have been working with a small team on a small project about fiction world building. I have been assigned with the task of managing triggers/chained behavior of entities (rocks/places/items) that can be triggered in many ways such as throwing a magic rock into the lake and monster X will appear, and continue to trigger the things in a chain until it reaches the end.

I have tried this

$Trigger_123 = new stdClass();
$Trigger_123->name = "Name";
$Trigger_123->renderOn = ? // (object_345->throwedInLakeX) ?

How can I store this in MySQL? Can I have it checked if its a chain part? Also I tried MySQL triggers but I can’t find a way to execute PHP on those triggers. Running PHP code on update or delete for example.

Cron jobs was not a option because many things will be added in the future and cron jobs will take a lot of time to finish, I was hoping of finding a more php-based solution.


Edited (adding some additional information)

I tried to implement this in many ways. I ended up with a system of dependecies pretty much like debian packages which I believe is not suited for this.

Database structure

Table "object"
--------------
ID (int)
Name (varchar)

Table "triggers"
----------------
ID (int)
Name (varchar)
Data (blob) // usually, I store php code and use eval to run

Table "attributes"
------------------
ID (int)
attribute (varchar)
value (blob)

Table "object_has_triggers"
---------------------------
ID (int)
ObjectID (int)
TriggerID (int)

Table "object_has_attributes"
-----------------------------
ID (int)
ObjectID (int)
AttributeID (int)

What I want as a result is to make a PHP code snippet execute each time

  • A database transaction , before is submitted and after to database
  • A object that has X triggers attached to it, resolve them
  • Each Trigger that is triggered by X be checked if all dependecies to it are satisfied

Question:
Is something like this even possible to build with PHP Or should I try other scripting languages like python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:19:45+00:00Added an answer on June 8, 2026 at 10:19 am

    A PHP code snippet execute each time a database transaction , before is submitted and after to database

    Don’t reinvent the wheel, this has an incredible simple solution: have a layer on top of your database calls.

    Instead of querying your database directly, call a function (perhaps in an object) that handles the database insertion of triggers. And it is right there that you can add your code to pre and post- process your triggers in whichever way you please.

    function processDatabaseInsertion($trigger) {
        //Preceding code goes here
    
        //Database transaction goes here
    
        //Post-processing code goes here
    }
    
    $Trigger_123 = new stdClass();
    $Trigger_123->name = "Name";
    $Trigger_123->renderOn = $object_345->throwedInLakeX;
    
    processDatabaseInsertion($Trigger_123);
    

    Over simplified, but you get the idea. I would recommend writing a custom class for your triggers but I wrote it in a procedural style since I don’t know if you are familiar with OOP.

    A PHP code snippet execute each time a object that has X triggers attached to it, resolve them

    Same principle as before. If you use PHP >= 5.3, you can spice it up a bit using closures:

    function processDatabaseInsertion($trigger) {
        //Preceding code goes here
        $trigger->renderOn();
    
        //Database transaction goes here
    
        //Post-processing code goes here
    }
    
    $Trigger_123 = new stdClass();
    $Trigger_123->name = "Name";
    $Trigger_123->renderOn = function() use ($Trigger_123) { doAwesomeThing($Trigger_123); }
    
    processDatabaseInsertion($Trigger_123);
    

    Or otherwise go for a more traditional approach:

    function processDatabaseInsertion($trigger) {
        //Preceding code goes here
        switch($trigger->renderOn) {
            case "awesomeThing":
                doAwesomeThing($trigger);
                break;
            case "anotherThing":
                break;
            default:
                break;
        }
    
    
        //Database transaction goes here
    
        //Post-processing code goes here
    }
    
    $Trigger_123 = new stdClass();
    $Trigger_123->name = "Name";
    $Trigger_123->renderOn = "awesomeThing";
    
    processDatabaseInsertion($Trigger_123);
    

    Each Trigger that is triggered by X be checked if all dependecies to
    it are satisfied

    Can easily be handled by the methods above with some more PHP logic as you will be able to tell. You may want to have for instance a generic function called every time you need to process a trigger which in turns check if dependencies are satistifed and runs the specific trigger if so.

    Either way there are better ways to tackle this problem than to use eval or some mysql trigger hacking as you can see 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a small file manager module in a project where
I have been working on a small project on recent delived ASP.NET MVC 3
I have this small project I have been working on. I have a MySQL
I have been working through a very small-scale WPF project in order to familiarize
I have a small project I have been working on. I had to create
I have been working on a small php app (400K total). But in the
I have been working on a project in C# (.net4). Project pretty much allows
I have been working on a project on and off, but I haven't touched
I have been working on a huge ETL project with 150+ tables and during
I have been working on a small Plagiarism detection engine which uses Idea from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.