A
A
Alexander2010-12-29 12:41:49
PHP
Alexander, 2010-12-29 12:41:49

PDO: INSERT array to table?

For mysql to insert many, many rows, you need to do something like
INSERT INTO ids VALUES
(0, ' url1.ru '),
(0, ' url2.ru '),
(0, ' url3.ru ');
so here's the problem: there is an array and it must be inserted into the plate. It is one-dimensional and, suppose that the column in the table is also one. Are there any PDO functions to implement this. Google did not give an answer .. (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2010-12-29
@Morfi

I do like this:

$stmt = $db->prepare('INSERT INTO ids VALUES (0, :url)');

try {
   $db->beginTransaction();
   foreach ($ursl as $url) {
      $stmt->bindValue(':url', $url);
      $stmt->execute();
   }
   $db->commit();
} catch (PDOException $e) {
   $db->rollBack();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question