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:

Any guidance appreciated.



superjacent’s picture

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


Steven Taylor

AuctionTeamster’s picture

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???

superjacent’s picture

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

samhassell’s picture

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.


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


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.


AuctionTeamster’s picture

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.

1kenthomas’s picture

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/

superjacent’s picture

Thank you for your input.

roychri’s picture

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:


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

codesidekick’s picture

We used user data extensively in one of our projects and I put together all the experiences we had from it and created a tutorial that teaches you how to use it!


The basic idea is that because you're storing serialized data you should create a wrapper class to deal with setting and getting the data. Then you can also use entity_metadata_wrapper to access those getters and setters and create a really strict and robust user data array.

Marton Bodonyi