A
A
Alexander2014-01-16 14:27:24
Yii
Alexander, 2014-01-16 14:27:24

What is the correct way to push a two-dimensional array of approximately [500][5] into the database?

Tell me how to correctly push a two-dimensional array of approximately [500][5] into the database?
How to bind everything in a loop in the example or is there a more elegant solution?

$post=new Post;
$post->title='тестовая запись';
$post->content='содержимое тестовой записи';
$post->create_time=time();
$post->save();

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2014-01-16
@s2nner

Understood. Yii 1.1.14 introduced this.
New method CDbCommandBuilder::createMultipleInsertCommand()
Using CDbCommandBuilder::createMultipleInsertCommand() it became possible to insert multiple records in one request:

$builder=Yii::app()->db->schema->commandBuilder;
$command=$builder->createMultipleInsertCommand('tbl_post', array(
  array('title' => 'record 1', 'text' => 'text1'),
  array('title' => 'record 2', 'text' => 'text2'),
));
$command->execute();

It is necessary to alter the array a little.

V
Vitaly Zheltyakov, 2014-01-16
@VitaZheltyakov

If you need a search in an array, then in any way in a loop. If not, then save either to a file, or serialize and write to the database.

M
Mikhail Shatilov, 2014-01-16
@iproger

"shove a two -dimensional array into the database? What prevents you from using the sirialize
& unserialize functions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question