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
    Check out this question and the answers, it's related. – birgire May 21 '14 at 13:23
1

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:

  • and what about BIT fields? they should be inserted as b'1' – Mariano May 22 '14 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. – Nicolai May 22 '14 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.