1

I'm preparing an insert query like this:

$wpdb->insert('table', $data, $format);

data array will be:

$data = array_push($data, 'resp' => true)

problem is, what $format shall i use for a boolean field?

$format = array_push($format, '%%')

in the codex i found only %s (for strings) %d (for integers) and %f (for floats)...but what about booleans?

1
  • 1
    Check out this question and the answers, it's related.
    – birgire
    May 21, 2014 at 13:23

1 Answer 1

4

BOOL or BOOLEAN are as far as MYSQL is concerned just replacements/synonyms for TINYINT(1), tiny integer, so using %d for integers is the correct way to do it.

Some additional information:

2
  • and what about BIT fields? they should be inserted as b'1'
    – Mariano
    May 22, 2014 at 6:30
  • @Mariano I don't know about the BIT type, I never used it in a wordpress/wpdb context, so can't help you there, but it's interesting, so you might want to ask another question. May 22, 2014 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.