The Log table is now created in Mysql, which is filled with the events of the tribes (INSERT) from other queries in the system.
The table contains information that needs to be expanded, for example, now the trigger ( INSERT AFTER ) has the form:

 BEGIN INSERT INTO log Set LogTime = NEW.ArticleTime, LogIdNote = NEW.idArticle, LogName = NEW.ArticleName, LogType = 1, logTypeCategory = NEW.ArticleCategory, LogIdUser = NEW.ArticleToUserID; END 

The problem is that for the trigger you need to add a couple more fields that are not in the NEW operator. For example, username:

 LogIdUser = NEW.ArticleToUserID; .... LogUserName = 'Username from current session PHP' 

Who has any suggestions and ideas?

  • Unless in triggers are forbidden? - etki
  • Hmm, did not know. But to make the desired select, you need to know the value of the PHP variables, (id_user, type_user session). - Jony
  • LogIdUser = NEW.ArticleToUserID; - isn’t it a user ID? - etki
  • It is, but the type is not. - Jony
  • Again we return: Is it really forbidden in triggers? - etki

1 answer 1

So ?

 CREATE TRIGGER article_insert AFTER INSERT ON `articles` FOR EACH ROW insert into log (LogTime, LogIdNote, LogName, LogType, LogIdUser) select NEW.ArticleTime, NEW.idArticle, NEW.ArticleName, NEW.ArticleToUserID, u.type from users u where u.id = NEW.ArticleToUserID; 

With session is similar. Is it stored somewhere in the database? If not, no way.

Threat NEW is not an operator, but a tuple containing the values ​​of the fields of the inserted records. Those. record one

  • Yes, something like this, but the fact is that depending on the type, the request is made either to users or animals . ____ The question is basically solved, you just need to make a SELECT nested query for a sample of type by id. - Jony