Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding multiple data with a single query #76

Open
zeydduran opened this issue Dec 22, 2020 · 3 comments
Open

Adding multiple data with a single query #76

zeydduran opened this issue Dec 22, 2020 · 3 comments

Comments

@zeydduran
Copy link

example :
$db->insert( [ 'tag' => 'asd', 'score' => rand() ], [ 'tag' => 'asd2', 'score' => rand() ], [ 'tag' => 'asd3', 'score' => rand() ], )->into('tags');
Or $db->insert([ [ 'tag' => 'asd', 'score' => rand() ], [ 'tag' => 'asd2', 'score' => rand() ], [ 'tag' => 'asd3', 'score' => rand() ], ])->into('tags');

@msarca
Copy link
Member

msarca commented Dec 22, 2020

We had something like this in 2013, but we removed it. I can’t remember why. Probably it was some sort of compatibility issue between different database systems. I believe that now it is safe to have something like this in the next release targeting PHP 8. @sorinsarca any thoughts on this?

@dj12djdjs
Copy link

I've seen an implementation similar to seen below in other libraries I've worked with.

/** @var \Opis\Database\SQL\InsertStatement $insert **/
$insert = $db->insert(columns: ['col1', 'col2', 'col3']);
foreach ($list as $record) {
  $insert->values([
      'col1' => $record['col1'],
      'col2' => $record['col2'],
      'col3' => $record['col3']
   ]);
}
$insert->into('table_name');

@brunoinds
Copy link

Any news about it? How can I use PDO::beginTransaction() and commit() to insert a multiple rows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants