Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL callback - is there such a thing?

Tags:

mysql

callback

I was wondering if there's such thing as the equivalent as a callback function using mysql after an INSERT or UPDATE which could return me the row # and maybe values of such rows.

like image 862
Itai Sagi Avatar asked Aug 28 '11 11:08

Itai Sagi


2 Answers

You can create triggers that are called on insert and update. They do not return value, but they can set variables you can read outside them.

like image 104
Maxim Krizhanovsky Avatar answered Oct 16 '22 02:10

Maxim Krizhanovsky


I am not aware of any callback as you say but surely from your calling application you can retrieve the last inserted ID in case you did not specify it and the db has generated an auto increment value. Other values you should already know because you have inserted them.

if you need to know those values within the database server, you can have a SQL trigger which is executed at every insert so you can do more processing on the newly inserted record, for example write something in another table etc...

like image 27
Davide Piras Avatar answered Oct 16 '22 02:10

Davide Piras