problem with unserializing data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alega
Forum Newbie
Posts: 3
Joined: Thu Feb 25, 2010 9:14 am

problem with unserializing data

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: problem with unserializing data

Post 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:

Code: Select all

$v = unserialize($h[0]);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
alega
Forum Newbie
Posts: 3
Joined: Thu Feb 25, 2010 9:14 am

Re: problem with unserializing data

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: problem with unserializing data

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: problem with unserializing data

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Re: problem with unserializing data

Post 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
Post Reply