0

Is there a way to make mysql automatically prepend a pre-defined string in a certain column to each new row? I have a script that automatically add links to the database but it's as follows: "//www.example.com/" and I don't have access to the PHP file inserting the data, I want to prepend "https:" automatically so that the data stored would be "https://www.example.com/".

medk
  • 9,233
  • 18
  • 57
  • 79
  • 1
    yes http://stackoverflow.com/questions/680801/how-to-prepend-a-string-to-a-column-value-in-mysql – Naranca Jul 04 '16 at 09:04
  • Thanks @Naranca but is there a way to do it directly in phpMyAdmin? in the column properties for example? – medk Jul 04 '16 at 09:08
  • 1
    Column definition can only have a default value `column_definition: data_type [NOT NULL | NULL] [DEFAULT default_value]` – Naranca Jul 04 '16 at 09:11

1 Answers1

1

You probably don't want to rewrite the query, because that's really error-prone and likely to completely go sour on you.

Instead, what you might want to do is define a trigger to react to any insert requests on the given table, and make it do an update after it, to modify the stored data.

Triggers are explained here: https://dev.mysql.com/doc/refman/5.7/en/create-trigger.html

Erik
  • 3,598
  • 14
  • 29
  • 1
    If a trigger can be avoided, take another path, but if you have no other option, triggers it is. – tadman Jul 04 '16 at 09:09