I need to set a trigger
so that every time you insert a data into a usuario
table, automatically insert the same data into another bkuser
table. How can I do this? Use PHP. And how do you invoke trigger
?
I need to set a trigger
so that every time you insert a data into a usuario
table, automatically insert the same data into another bkuser
table. How can I do this? Use PHP. And how do you invoke trigger
?
The trigger is relative to the database, not the language.
A trigger is created just to be invoked automatically before or after something.
For example, I can create a log for auditing, always after I update some record in the table that has the trigger. Example:
create table usuarios (
id int primary key auto_increment,
nome varchar (45) not null
);
create table usuarios_alteracoes_historico (
id_usuario int not null,
nome varchar (45) not null,
constraint fk_usuario_historico_alteracao foreign key (id_usuario) references usuarios (id)
);
CREATE TRIGGER usuarios_salva_historico
AFTER UPDATE ON usuarios
FOR EACH ROW BEGIN
INSERT INTO usuarios_alteracoes_historico (id_usuario, nome) VALUES
(NEW.id, OLD.nome); END//
insert into usuarios (nome) values
('william'), ('roberto');
update usuarios set nome = 'william okano' where nome = 'william';
select * from usuarios;
select * from usuarios_alteracoes_historico;
In case of "activating the trigger", you simply insert an insert into the table that will be "transparent" for you to insert into the history table.
It's up to you now to adapt to what you need, because your question is poorly crafted and confusing.