I've written a desktop application that converts Wordpress blogs to Drupal 5.x (now in the process of configuring it for Drupal 6.x).

Could someone explain the meaning of the data field of the users table. I note that under a clean fresh installation of Drupal the data field for a user is recorded as such a:1:{s:7:"contact";i:0;}. For conversion purposes from Wordpress to Drupal, I've merely copied this and everything works.

I also note that after usage the data field can appear like so:
a:5:{s:16:"profile_homepage";s:21:"http://www.google.com";s:17:"captcha_challenge";s:2:"10";s:7:"contact";i:1;s:14:"picture_delete";s:0:"";s:14:"picture_upload";s:0:"";}

Any guidance appreciated.

Steve
http://prime357.org

Comments

Anyone or at least point me in the right direction (nicely).

___________________________

Steven Taylor
http://prime357.org

___________________________

Steven Taylor
Prime 357

I have been searching the forum for the answer to your same question as well as others related to the data field. As much as I can appreciate the work that has gone into the developement of Drupal -- I yet can't fathom why your question as gone unanswered for so long -- as for me -- when I finally make it up the Drupal Curve -- I pledge to do my best to answer these matter-of-fact type questions in they are within my framework of knowledge. DID YOU EVER FIND THE ANSWER???

Never did get an answer, never ever got anything close to an explanation. I've worked out the structure of the data stored in the data field, which I'm sure you have as well but I'll put forward my explanation anyway. It's basically an array of key/value pairs and as best as I can make out all modules or any modules that reference the user table (the user) somehow access and manipulate the data.

For a default installation a:1:{s:7:"contact";i:0;}
a:1 means an array containing one key/value pair.
{s:7:"contact";i:0;}string value, 7 characters length and actual value "contact" (note 7 chars length). i = integer value and "0" being integer value.

I suppose this data field can be considered a sort of options table relative to the user which probably speeds things up for every other module that wants to store user optional stuff, saves queries having to open up specific optional tables to retrieve the data.

___________________________

Steven Taylor
http://prime357.net

___________________________

Steven Taylor
Prime 357

The data field can be used to store user data. it is encoded using the php serialize() function, which converts an array to a storable format.

http://au.php.net/serialize

when you are using the Drupal user_save() function you can set these variables and retrieve them with user_load()

http://api.drupal.org/api/function/user_save/5
http://api.drupal.org/api/function/user_load/5

Beware that it is not considered best practice to store a lot of data like this as it can cause bottlenecks when creating user objects. Better to create another table and use hook_user to add content from your table to the user object.

HTH.

Thanks for the response -- Its really odd because the prevailing thought is not to use it -- "the data field" if you can avoid it -- however this places severe limitations on your ability to enhance your user registration process (opt in to customized email list -- ect.). Yet if you do use it -- its not searchable for database query unless the info has been updated -- which of course the user may never do.

Additionally, when you try to submit the data to an alternate table -- the data is hijacked by the data field by default resulting in null values to your newly created table.

I really dont know the answer -- maybe the answer is to punt -- but for now I am going to persist and experiment with using hook_alter-form to see if I can resolve any of these and other unnamed problematic issues.

Generally, people answer questions as they can, as they see them, as they feel merit. Snide responses do not help, for what is a free, volunteer support system.

This is a serialized array for storing parts of the $user object. Unless you understand serialization, serialized arrays, and what's going on, you most likely wish to use user_load() and user_save() functions. Explaining the previous is largely outside the purpose of this forum.

Good luck,

Ken Thomas
Horton Group, http://www.hortongroup.com/

Thank you for your input.

___________________________

Steven Taylor
Prime 357

Assuming the serialized data present in the original post of this tread:

If you need to extract some value using SQL, here is how I got it done:

SET @name:='profile_homepage' ;
SELCT @pos1:=LOCATE(CONCAT(':"',@name,'";'), data)+LENGTH(CONCAT(':"',@name,'";')) AS 'pos1',
      @pos2:=LOCATE(';', data, @pos1) AS 'pos2',
      SUBSTRING(data, @pos1, @pos2 - @pos1) AS 'value'
FROM users QHERE uid = 4\G

This query returned me:

s:21:"http://www.google.com"

Simply change 'profile_homepage' with the name of the data field you want and 4 by the user id.

--
PHP5 Zend Certified Engineer
Christian Roy

--
Drupal Freelancer (Module Developer)
Christian Roy