I transfer the site from the crutch framework to my engine, this problem arose:

In the database table, such paths to the pictures: audi/1.jpg , bmw/1.jpg , etc. You need to add paths with the substring /uploads/catalog/ , i.e. paths should be /uploads/catalog/audi/1.jpg

The directory is large, manual editing is not an option.

Question: How can I fill in all the records in this field with a substring with one sql query?

  • one
    there were great ways. The common part for all is best stored somewhere in the application settings. what would: 1. not edit the entire database, if you suddenly need to change the path. 2. Whatever long strings take up extra disk space. Large lines reduce performance - Mike
  • Not an option, CKFinder is used in the admin site, for it, by default uploads is the root directory, and when I select a file, this is the way uploads/... returns, and do I have a lot of memory if I have to substitute uploads/catalog/ , there are a lot of modules in the engine and each has its own folder in /uploads , besides, I write simple informational websites on this engine, and spending time and complicating the code to save a couple of megabytes is not the case - Anatoly Shevelev
  • and this should be by no means in the templates. and in the code that gets this path from the database for example (if of course there is a guarantee that the path is the same everywhere). The idea is that any constant of this kind should be somewhere in the system only in a single copy, which would then be easier to fix, if necessary. But yes, in the absence of something else, the DB is a better option compared to the templates, it is clearly easier to fix than to bunch of files - Mike

1 answer 1

 update table set field = CONCAT("/uploads/catalog/", field) 
  • Thank you for what you need;) - Anatoly Shevelev