Unserialize a record from ispconfig database

Discussion in 'General' started by smartcall, Dec 3, 2007.

  1. smartcall

    smartcall ISPConfig Developer ISPConfig Developer

    Hi,

    I've been trying to unserialize the data field from isp_fakt_rechnung table but it returns FALSE.
    I need this in order to get the web_id for the particular invoice.
    What am I mistaking?

    Thanks.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    To unserialaize a record, try:

    $myarray = unserialize(stripslashes($myvar))

    Also you might want to try the XML version instead.
     
  3. smartcall

    smartcall ISPConfig Developer ISPConfig Developer

    Thank you,

    I wrote this small code and name it test.php in a web:
    Code:
    <?php
    $myvar = 'a:1:{i:10;a:1:{i:13;a:1:{i:59;a:7:{s:6:"anzahl";s:1:"1";s:4:"type";s:3:"Web";s:6:"nummer";s:3:"321";s:4:"name";s:28:"Free
     (anton.joomla-bg.net)";s:4:"text";s:0:"";s:5:"preis";s:1:"0";s:3:"vat";s:3:"16%";}}}}';
    $myarray = unserialize(stripslashes($myvar));
    var_dump($myarray);
    ?>
    $myvar is a record from the ispconfig database.

    and when I load it i get 'bool(false)' result.

    Regards!
     
    Last edited: Dec 4, 2007
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Normally it should work this way.

    Please have a look at the file /home/admispconfig/ispconfig/web/isp_fakt/view/view.php

    Here the relevant part:

    Code:
    $rechnung_id = intval($HTTP_GET_VARS["rechnung_id"]);
    $rg_record = $go_api->db->queryOneRecord("SELECT * from isp_fakt_rechnung where rechnung_id = $rechnung_id");
    
    $rechnung = unserialize(stripslashes($rg_record["data"]));
    (rechnung = invoice :)
     
  5. smartcall

    smartcall ISPConfig Developer ISPConfig Developer

    I edited my previous post and put my code in. /home/admispconfig/ispconfig/web/isp_fakt/view/view.php is where I got it from.
    I know german:)
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Then I have no idea, your code looks fine. Maybe the serialized string is somehow broken. PHP is a bit picky regarding unserialization.
     
  7. smartcall

    smartcall ISPConfig Developer ISPConfig Developer

    One of the reasons could be, because I don't use the ispconfig php. For this test I use the clients' php.
    When I look at this client's invoices from ispconfig interface they show right.
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Until now I had not seen any problems with different PHP versions regarding serialization. The forms in ISPConfig are serialaized too and we updated trough several PHP versions in ISPConfig until now and this never broke.

    Have you tried to use the XML version of the stored invoice instead? If you use simplexml, it should be easily accessible from PHP.
     
  9. smartcall

    smartcall ISPConfig Developer ISPConfig Developer

    I will try. Thanks for your time.
    But if there is another way to find the web_id from the tables related to the invoices it will do too.
    My goal is to count invoices for free webs per client and if there are more than N for a web, then I will suspend the web.
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    There is no other way to get the web ID as to unserialize the data or read the xml.
     
  11. smartcall

    smartcall ISPConfig Developer ISPConfig Developer

    Yes. Thanks a lot. simplexml is a very nice solution.
     

Share This Page