I was trying to save term with name "Big Honor for Branford's Le Petit Café" using taxonomy_term_save function which throws me the following error

PDOException: in drupal_write_record() in common.inc 

Is it some thing related to character encoding ? should i have to convert the character? I am not sure how to do that.

Please find the code that throws the error,

$term_name  = new stdClass();
$term_name->name = urldecode("Big%20Honor%20for%20Branford%27s%20Le%20Petit%20Caf%E9");
$term_name->vid = 1;

If we are using the exact "Big Honor for Branford's Le Petit Café" is a file then i could not get the error but, when url encoded and decoded again, we will have the same character set.

  • 2
    You will have to dig up the actual PDO excetion. Ensure logging is on, and check the database log or webserver logs as approprite. I can see no reason why the term should fail to save due to character encoding. – Letharion Sep 7 '12 at 7:02
  • actually the name should be escaped automagically, are you passing a $term object ? – rémy Sep 7 '12 at 8:49
  • Yes but it is not – Dinesh Kumar Sarangapani Sep 7 '12 at 10:27

This code works perfectly for me:

$term = (object)array(
  'name' => "Big Honor for Branford's Le Petit Café",
  'vid' => 1


No errors, and the term is saved as expected. So it looks like the issue is something to do with your server configuration. Without more details it's impossible to say what that problem might be though.


Turns out this a multibyte encoding issue. Wrapping the string in utf8_encode() will fix it:

$term_name->name = utf8_encode(urldecode("Big%20Honor%20for%20Branford%27s%20Le%20Petit%20Caf%E9"));
| improve this answer | |
  • Opps my mistake, I have updated the code you have to try. – Dinesh Kumar Sarangapani Sep 7 '12 at 10:25
  • You're suffering from an encoding issue, I've added a bit to the answer that should help – Clive Sep 7 '12 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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