I have some pretty straightforward code that combines some string values together and then writes them to the db using drupal_write_record(), and it seems that the values are getting cut off for some reason when actually written to the database.

$keys_string = str_replace('|', '', $product->attribute_keys);
$values_string = str_replace('|', '', $product->attribute_values);

$keys = array_filter(explode('~', $keys_string));
$values = array_filter(explode('~', $values_string));

$description = '';
foreach ($keys as $key => $data) {
    $description .= $keys[$key] . ' : ' . $values[$key] . "\n";

$description .= "\n" . $product->group_text; 

// Write record to database.
$table = 'ridethis_combined';
$record = new stdClass();
$record->title = $title;
$record->description = $description;
$record->short_description = $product->group_text;
$record->upc = $product->upc;
$record->sku = $product->vendor_item_id;
$record->cost = $price;
$record->price = $price;
$record->bti_quantity = $product->available;
$record->hawley_quantity = NULL;
$record->weight = NULL;
$record->manufacturer = $product->manufacturer_name;
$record->image = $image_url;
$record->meta_description = $product->group_text;
$record->meta_keyword = $product->group_text;
$record->meta_title = $title;

drupal_write_record($table, $record);

When stepping through the code in a debugger, I can see that prior to drupal_write_record, the full concatenated value is is stored in $record->description. However, when I view the data in MySQL, only the concatenated values from $product->attribute_keys and $product->attribute_values is there; it's as if the $product->group_text data was never there. The size of the db field is not an issue, since it has plenty of space for the content I'm writing to it.

Do you have any thought on what could be cutting this text off?

  • Does the description column in MySQL is big enough to store the datas ? Does this table has a schema which would have an incorrect size for this column ?
    – tostinni
    Sep 20, 2011 at 4:53
  • As I stated above, the size of the db field is not an issue, since it has plenty of space for the content I'm writing to it.
    – wonder95
    Sep 20, 2011 at 4:57
  • Can you post the CREATE syntax for your table?
    – cam8001
    Sep 20, 2011 at 14:02
  • 1
    There may be an issue with your use of \n in the string. Try using \\n or removing it entirely.
    – cam8001
    Sep 20, 2011 at 14:05
  • @cam8001 drupal_write_record() is present in Drupal 6 and forward; you implement hook_schema() to define the database tables used by a module.
    – apaderno
    Nov 6, 2011 at 13:40

1 Answer 1


The function drupal_write_record() uses the database schema defined from the module. Check your hook_schema(), and see if it has the right length.

Post your hook_schema() implementation too, if this doesn't help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.