Page 1 of 1

Using stored procedure in a hook

Posted: 2023-02-27 14:36
by ojoerk
Hello,
I created a stored procedure in MariaDB, which works well. Now I wanted to use it in the table_after_insert() hook. I could imagine to do it like this:

$db->query('call insertMaintenance('.$data['ResourceId'].', '.$data['EndDate'].');');

But where does this $db object comes from? Do I have to create a new one or is there still one available from the previous insert operation?
Thank you for pointing me to the right direction.

Olaf

Re: Using stored procedure in a hook

Posted: 2023-02-27 17:01
by ojoerk
I found the sql()function and tried:

sql("call insertMaintenance('".$data['ResourceId']."', '".$data['EndDate']."')", $error);

But then I'm getting an "out of sync" error. Nevertheless, the data was inserted to the database. How can I avoid this error?

Re: Using stored procedure in a hook

Posted: 2023-03-15 22:43
by angus
maybe try

Code: Select all

sql("call insertMaintenance('".$data['ResourceId']."', '".$data['EndDate']."')", $o);