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

setUpdateBatch #4025

Closed
hanmoguoke opened this issue Dec 24, 2020 · 3 comments
Closed

setUpdateBatch #4025

hanmoguoke opened this issue Dec 24, 2020 · 3 comments

Comments

@hanmoguoke
Copy link

hanmoguoke commented Dec 24, 2020

function setUpdateBatch Must be a two-dimensional array or object,

The document is:

setUpdateBatch($key[, $value = ''[, $escape = NULL]])
Parameters: | $key (mixed) – Field name or an array of field/value pairs
$value (string) – Field value, if $key is a single field
$escape (bool) – Whether to escape values and identifiers

Adds field/value pairs to be updated in a table later via updateBatch().

How to use it?
What I want to achieve is not to escape data when batch updatewith updateBatch

@hanmoguoke hanmoguoke added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 24, 2020
@iRedds
Copy link
Collaborator

iRedds commented Dec 27, 2020

Description of fields is incorrect

$data = [
   [
      'id' => 1,
      'title' => 'My title' ,
      'name'  => 'My Name 2' ,
      'date'  => 'My date 2'
   ],
   [
      'id' => 2,
      'name'  => 'Another Name 2' ,
      'date'  => 'Another date 2'
   ]
];
$db->setUpdateBatch($data, 'id', false)
$db->updateBatch(null, 'id')
// or 
$data = [
   [
      'id' => 1,
      'name'  => 'My Name 2' ,
      'date'  => 'My date 2'
   ],
   [
      'id' => 2,
      'name'  => 'Another Name 2' ,
      'date'  => 'Another date 2'
   ]
];
$dataNotEscape = [
   ['title' => 'My title'],
   ['title' => 'Another title']
];

$db->setUpdateBatch($dataNotEscape, 'title', false)
$db->updateBatch($data, 'id')

@paulbalandan paulbalandan removed the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 29, 2020
@paulbalandan
Copy link
Member

Both examples of @iRedds are correct. If you need no escaping, just set the $escape param of setUpdateBatch to false.

@hanmoguoke
Copy link
Author

thank u! it works!

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

3 participants