1
array
  0 => 
    array
      'id' => float 1110
      'description' => string 'Culture de céréales (à l'exception du riz), de légumineuses et de graines oléagineuses' (length=86)
      'field2' => float 11
      'field3' => float 26.631
  1 => 
    array
      'id' => float 1120
      'description' => string 'Culture du riz' (length=14)
      'field2' => float 11
      'field3' => float 7.556

With this array what is the correct process for the string "description" to avoid SQL error when data is added with db_insert ?

I use this code for multiple insert :

$query = db_insert('table')->fields(array('id', 'description', 'field2', 'field3'));

foreach ($sql_query as $record) {
     $query->values($record);
}

$query->execute();

// $sql_query is the array described above.
6
  • What's the error?
    – Clive
    Commented Aug 10, 2015 at 9:44
  • In backend (rapport tab) : PDOException : in _mymodule_addrow() line 87 ... In fontend I have the default error page of Drupal without any explanation.
    – Promo
    Commented Aug 10, 2015 at 9:47
  • Check your logs and watchdog, the real error message is in there. We need to know what it says
    – Clive
    Commented Aug 10, 2015 at 9:48
  • In the log it's only displayed: "PDOException : in _mymodule_addrow() line 87" + file path but without details... :'(
    – Promo
    Commented Aug 10, 2015 at 9:56
  • 1
    Could you make a title here bit more unique and informative? We have hundreds (if not thousands) questions about insert queries.
    – Mołot
    Commented Aug 10, 2015 at 14:10

1 Answer 1

1

The data come form a file where string were not convert to utf8 at the opening thus the Drupal 7 parsing function for database query couldn't convert string to avoid SQL error.

Sorry but I didn't think that the problem could be as much upstream...

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.