O
O
Optimus2015-11-20 22:51:04
PHP
Optimus, 2015-11-20 22:51:04

How to add all Ivan Ivanovich with one request?

There is an array that needs to be entered into the database:

$people = array('Иван Иваныч', 'Сергей Сергеич', 'Сидор Сидорович');
for(){
    $b=$pdo->prepare(" INSERT INTO `organization` SET name=:name ");
    $b->bindParam(":name",$people[$i]);
    $b->execute();
}

But it seems like it's not good to put requests inside the cycle. How to do it right in this case, maybe PDO has some special features for this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill, 2015-11-20
Pyan @marrk2

Something like this is correct:

$people = array('Иван Иваныч', 'Сергей Сергеич', 'Сидор Сидорович');
$b=$pdo->prepare(" INSERT INTO `organization` SET name=:name ");
for(){  
    $b->bindParam(":name",$people[$i]);
    $b->execute();
}

But, as far as I remember, pdo prepare statements don't really work
PS: maybe it's not too late for this pdo with php? ;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question