Updateing Codeblock with SQL Statement

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:

global $conn;
include './twl/dbconnect.php';

followed some more code and it ends with


However this code is not displayed in the gallery admin at all. codeblock is completely empty there.

Any ideas how to solve this?


  • acrylian Administrator, Developer
    edited September 18

    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…

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

Sign In or Register to comment.