Page 1 of 1
problem with unserializing data
Posted: Thu Feb 25, 2010 9:21 am
by alega
Hi,
i need help on following:
<?php
$connect = mysql_connect("sql113.0fees.net", "fees0_4998969");
mysql_select_db ("fees0_4998969_gielel");
$select = "SELECT `user_data` FROM `ci_sessions`";
$i = mysql_query($select);
$h = mysql_fetch_row($i);
print_r($h); // - this returns serialized array
// if i write: $v = unserialize($h); print_r($v);
// it would return nothing
?>
what i'm doing wrong?
Re: problem with unserializing data
Posted: Thu Feb 25, 2010 9:28 am
by AbraCadaver
mysql_fetch_row() does not return a serialized array, it returns an array of the columns and data from the query result. To access the the returned column you would use $h[0]. You might like mysql_fetch_assoc() better as you can then use $h['user_data']. If you mean that the contents of `user_data` is serailized, then you would use:
Re: problem with unserializing data
Posted: Thu Feb 25, 2010 9:49 am
by alega
thanks for answer!
now i use:
$h = mysql_fetch_assoc($i);
$v = unserialize($h['user_data']);
print_r($v);
but again it returns nothing, though:
$d = ($h['user_data']);
print_r($d); // returns serialized object
Re: problem with unserializing data
Posted: Thu Feb 25, 2010 9:54 am
by AbraCadaver
Are you sure it's an object? If so then you need to include the class that the object is instantiated from before you unserialize it.
Re: problem with unserializing data
Posted: Thu Feb 25, 2010 10:10 am
by AbraCadaver
Also, now that I re-read your first post, is it possible that this data is being written to the DB by the session handler? If so the serialized data is a different format from the serialze() function. There is no internal function that you can use to unserialize this that I know of. You'll either have to search for a hack or serialize it yourself before inserting it.
Re: problem with unserializing data
Posted: Thu Feb 25, 2010 10:11 am
by dude81
Hello alega,
It is really not good to put your mysql user information on to the forums. consider changing it to some random values.
Thank You
dude