P
P
Pavel2015-08-13 16:07:11
Drupal
Pavel, 2015-08-13 16:07:11

db_insert throws a PDOException when creating a row with implode(). Why?

In general, the fact is that when you try to add a row to the database, when forming it through implode (), a PDOException error pops up:
This does not work:

<?php
$test_array = array('Apple', 'Banan');
$test = implode($test_array, ", ");

db_insert('test')
  ->fields(array(
    'nid' => 2,
    'related' => $test,
    'created' => time(),
  ))
  ->execute();

And that's how it works
<?php

$test = 'Apple, Banan';

db_insert('test')
  ->fields(array(
    'nid' => 2,
    'related' => $test,
    'created' => time(),
  ))
  ->execute();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2015-08-13
@pantey

In general, the problem was in the encoding, I did not understand why, but
I solved the problem

N
Nazar Mokrinsky, 2015-08-13
@nazarpc

The arguments were mixed up in places, at least they looked at the logs, it’s probably written there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question