Pass PHP variable to MySQL trigger #nette

7 months ago

WilliamTi
Member | 2
+
0
-

I have trigger created in my database. I need to pass PHP variable to that trigger.

I tried executing something like this in PhpMyAdmin:

SET @myVariable = 123;
INSERT INTO table (foo) VALUES (bar);

Trigger successfully take @myVariable – So I tried it in Nette project, but I was not successfull.

First, Prepared Statement can execute only one command, so I am not able to call SET and INSERT together.

Then I found information that variable should be valid for whole connection, so I tried call:

$database->query('SET @myVariable = 123');

After connecting to database. Then I tried INSERT. But again, I was not successfull.

Anybody have any idea how to pass PHP variable to trigger?

7 months ago

David Grudl
Nette Core | 6877
+
0
-

I tried

$database->query('SET @myVariable = 123');
var_dump($database->query('SELECT @myVariable')->fetch());

and it prints @myVariable => 123, so it should work with INSERT too.

What exactly does the INSERT do?