MySQL Email Templates .. Is this Possible?

Not sure if this is possible, but it's worth it. I am trying to insert some text into the MySQL TEXT field. Some words in the text that I want to change, depending on other fields from some other tables in the MySQL database .. Something like php email template, where "Expensive $ {first_name}" can be changed depending on what who is sent an email ...

Is it possible to do something like this in a field in a MySQL table?

I know that this can be done using a PHP file, but I was wondering if this can be done using MySQL ..

+4
source share
1 answer

Yes, I think you could do this using a stored procedure.

It would have to have a REPEAT loop that uses LOCATE to find the row index of the next token '${' , takes a name from there to the next LOCATE d '}' and replaces CONCAT and SUBSTRING with a value. If this value comes from a simple table of matching names to a value that is not so bad, but if you want ${first_name} actually use a column named first_name , you would need to create dynamic SQL in the row and run it using PREPARE...EXECUTE that is ugly and dangerous.

It would be complex, fragile, and dependent on the DBMS. SQL is not really intended for convenient use. Any universal programming language with reasonable string manipulation tools should be able to do this in a much simpler way. If you have PHP, use it.

+1
source

All Articles