ZenphotoCMS Forum
Updateing Codeblock with SQL Statement - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: Translating (https://forum.zenphoto.org/forum-8.html)
+--- Thread: Updateing Codeblock with SQL Statement (/thread-13747.html)



Updateing Codeblock with SQL Statement - tw2003 - 18-09-2022

I need to update all codeblocks I used with several hundereds of my pictures as I want to change some things.
I'm able to run the update in phpmyadmin and see the correct result in corrsponding field. However if I open the gallery as admin the codeblock section is empty.
The update statement is like this:
update zp_images set codeblock=REPLACE(codeblock, '$conn = new mysqli(\"ip-adress\", \"user\", \"password\", \"datbasename\");', 'global $conn;\ninclude \'./twl/dbconnect.php\';\n');

This is the how the beginning of the codeblock field with the change looks in phpmyadmin:
a:1:{i:1;s:1428:"




Updateing Codeblock with SQL Statement - acrylian - 18-09-2022

You can have several codeblocks so the data is stored seralized. You have to cover that with your statement. I fear you cannot do this via MySQL easily directly. BEtter use PHP and Zenphoto's object model for this:

  • First get the data
  • unserialize it to get an array of all codeblocks,
  • update the array entry you want
  • Store it again serialized

Each object has methods for these tasks.

Also: If you do things like this perhaps consider to edit the theme itself (using the multiple_layouts plugin for example). Codeblocks are rather a workaround for simple calls. Today I would not introduce them as a feature anymore. Just beacuse maintainance is quite a pain if you used them a lot in various ways…




Updateing Codeblock with SQL Statement - tw2003 - 20-09-2022

Thanks for explaining. At least I was not too stupid to do the correct SQL statement :-)