golem Posted December 13, 2006 Share Posted December 13, 2006 HI ,I try to store an array in MySQL db. here is whay I Do:----------------------------------------------------------------------------------------function insertArray($sArray){//------($sArray is an array with 3 strings: "One","Two","Three" )//db connect stuff...include("config.php");//connect to the mysql server$link = mysql_connect($server, $db_user, $db_pass);// select the databasemysql_select_db($database); // //serialize the array $DB_array = serialize($sArray); $user = "user1"; //update the db $query = mysql_query("UPDATE $table SET location = '$DB_array' WHERE username = '$user'"); // get the array from db $query = mysql_query("select location from $table where username = '$user'"); // get the 'location' field $field = mysql_fetch_row($query);//if I try return here: return $field I get: a:3:{i:0;s:3:"One";i:1;s:3:"Two";i:2;s:5:"Three";} //unserialize the 'location' field $return_array = unserialize($field); return $return_array; }------------------------------------------------------If I look in the db, the 'location' field has a serialized looking string:a:3:{i:0;s:3:"One";i:1;s:3:"Two";i:2;s:5:"Three";}if I return $field I get this same string, but when I try to unserialize it it fails....I NEED HELP!!!! ??? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 13, 2006 Share Posted December 13, 2006 using this line:[code]$field = mysql_fetch_row($query);[/code]you are retrieving the object that is that row. You need to use the mysql_result function:[code]$query = mysql_query("select location from $table where username = '$user'");$field = mysql_result($query, 0, "location");$return_array = unserialize($field);[/code] Quote Link to comment Share on other sites More sharing options...
golem Posted December 13, 2006 Author Share Posted December 13, 2006 :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-* :-*[b][color=red]THANK YOU![/color][/b] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.