13
caiofior
352d

Fixing a Woocommerce order editing manually a php serialized object in db. 😨️

Comments
  • 2
    that's next level
  • 4
    @We3D It also worked: now I'm officially a PHP human interpreter. Some programmers use AI to interact with servers. I'm a slave of a server. It uses my neurons to solve his problems
  • 2
    serialize can be useful but frankly speaking I'd rather have a json string.

    The PHP associative array

    [ '692_1' => 'completed', '692_5' => 'completed', '692_2' => 'completed', '692_3' => 'completed', '692_4' => 'completed', '692_6' => 'completed']

    can be serialized as

    a:6:{s:5:"692_1";s:9:"completed";s:5:"692_5";s:9:"completed";s:5:"692_2";s:9:"completed";s:5:"692_3";s:9:"completed";s:5:"692_4";s:9:"completed";s:5:"692_6";s:9:"completed";}

    which is a 174 characters string or json encoded as

    {"692_1":"completed","692_5":"completed","692_2":"completed","692_3":"completed","692_4":"completed","692_6":"completed"}

    which is a 121 characters string.

    Databases can understand json, so I'd rather use that if possible. Serialize can do things that json can't, like dealing with objects and non-public properties but it's a hideous mess and it can get ugly with things like Closures and recursive objects.
  • 2
    What's the surprise here? Your using WorstPress.

    Gravity forms has a similar hell scape. It's freaking annoying to work with.

    I will say this though, if you find yourself working with these kinds of serialized Json objects all the time I definitely recommend making a custom plug-in that uses the woocommerce API methods to serialize it for you and update the database.
  • 1
    Real men use EXI and binary fields for serialization!
  • 1
    @We3D "I know this!'
  • 1
    @iSwimInTheC but have you tried bson?
  • 1
    @Wisecrack 😂. Mmm my favorite
  • 1
    @iSwimInTheC but have you tried...nonstandard undocumented protocols over RPC?
Add Comment