Update database data on a PostCreate event
Update database data on a PostCreate event
borconi
Posts: 56Questions: 19Answers: 1
Hi.
Is it possible to update the newly created row from PHP without making a separate call to the script?
I'm trying to do something like this:
$editor->on( 'postCreate', function ( $editor, $id, $values, $row ) use ($db) {
$db->query("update `events` set `folder`=concat(`eventid`,' - ',`folder`) where `eventid`=$id");
} );
But I have a feeling that the postCreate
event is fired before the actual commit to the db making the update query useless.
Any thoughts on how this can be achieved?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can indeed do what you are looking for, but I think the issue you are seeing with the above is that
$db
is probably a different database reference to the one that Editor is using.Since, as you say, Editor is in a transaction, you would need to use the Editor db link:
will do it. Or you can use the abstraction methods for a little more security.
Allan
Thank you!