Page 1 of 1

Execute MySQL stored procedure on trigger

Posted: Mon May 15, 2017 4:02 am
by shuqierduo
I have a trigger 'insertData' to execute a MySQL stored procedure 'createData'. I have no problem executing the sp but when I execute a workflow with the trigger, it prompts "Error" instead.

What did I miss?

Table 'TEST1' contains an auto inrement column, 'auto_inc_id'

Trigger 'insertData' code:

$db = "13849224459j2345e6846c20533032345";
$sql = "call createData(102)";
$result = executeQuery($sql, $db) or die ("Error");

MySQL SP 'createData' code:

CREATE PROCEDURE `createData`(
IN
appID int(11)
)
BEGIN
DECLARE newID INT DEFAULT 9999;

INSERT INTO TEST1 (
auto_inc_id
) VALUES (
appID
);
SELECT max(auto_inc_id) INTO newID FROM TEST1 WHERE auto_inc_id = appID;

INSERT INTO TEST2 (
auto_inc_id
) VALUES (
newID
);
END

Re: Execute MySQL stored procedure on trigger

Posted: Mon May 15, 2017 5:47 am
by mishika
Hello,

To execute a procedure from the ProcessMaker trigger, you will have to use the following code:
Code: Select all
$db = "13849224459j2345e6846c20533032345";
@@sql = "CALL createData('55')";	//take these variables as case variables. This will always help in debugging the problem
@@result = mysql_query(@@sql);
This is because the PM trigger will not execute a procedure using the function executeQuery().
To execute a procedure from trigger you will have to use the PHP function mysql_query().
You can check the problem occurring in your code by considering the variables as case variables rather than PHP variables and running the process in debug mode.
If the code works fine, you will get "true" for @@result in debug mode otherwise "false".

Hope this helps

Best Regards