title: MYSQL update Trigger check changes in all columns and insert values to other table
body: <p>I've come to this code, but from this i have to manually insert all columns and check it by each column</p>
  
  <pre><code>CREATE TRIGGER table_a_update BEFORE UPDATE ON table_a
  FOR EACH ROW     
  BEGIN
     IF (NEW.column1 &lt;=&gt; OLD.column1) 
     THEN
         INSERT INTO table_updates(table, object_id, user_id, column, old_value, new_value)
         VALUES ("table_a",NEW.id, NEW.user_id, "column1", OLD.column1, new.column1)
     END IF;
     IF (NEW.column2 &lt;=&gt; OLD.column2) 
     THEN
         INSERT INTO table_updates(table, object_id, user_id, column, old_value, new_value)
         VALUES ("table_a",NEW.id, NEW.user_id, "column2", OLD.column2, new.column2)
     END IF;
     (other columns... ifs)
  END;
  </code></pre>
  
  <p>I want to know how could i get all the columns from NEW that have differences to OLD columns, and then insert it, by something like this example using a php to what i dont know:</p>
  
  <pre><code>BEGIN
      for(columns(NEW) as $column){
          IF (NEW.$column &lt;=&gt; OLD.$column)
          THEN
              INSERT INTO table_updates(table, object_id, user_id,column, old_value, new_value)
              VALUES ("table_a", NEW.id, NEW.user_id, $column, $OLD[$column], $NEW[$column])
          END IF;
      }
  END;
  </code></pre>