PDA

View Full Version : Unserialize a record from ispconfig database


smartcall
3rd December 2007, 18:53
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.

till
3rd December 2007, 21:17
To unserialaize a record, try:

$myarray = unserialize(stripslashes($myvar))

Also you might want to try the XML version instead.

smartcall
4th December 2007, 08:37
Thank you,

I wrote this small code and name it test.php in a web:
<?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!

till
4th December 2007, 08:50
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:

$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 :)

smartcall
4th December 2007, 08:56
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:)

till
4th December 2007, 09:13
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.

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

smartcall
4th December 2007, 09:17
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.

till
4th December 2007, 09:21
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.

smartcall
4th December 2007, 09:27
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.

till
4th December 2007, 09:31
There is no other way to get the web ID as to unserialize the data or read the xml.

smartcall
4th December 2007, 09:38
Yes. Thanks a lot. simplexml is a very nice solution.