What's the equivalent data type for boolean (0/1, True/False) in mySQL?
Boolean in mySQL?
Umm... maybe the MySQL manual can help you here?
Already checked it. Didn't find what I'm looking for.
Try the type BOOL.
This is actually a compatibility thing because it really uses a tinyint(1).
Are you sure it uses TinyInt(1) because then 0 won't be false and 1 won't be true when the values are seeked?
BTW, did'nt find a BOOL type either.
I did:
create table test (a bool);
describe test;
and it said tinyint(1). :-)
0 is always false, and 1 is always true. Its this way in any language.
---John Holmes...
I would suggest:
1) There is no Boolean-Type in mySQL, but when you define a table, use BOOL as a synonyme for TINYINT(1):
create table
2) a value of 0 means false, any other integer apart from 0 means true. the value can also be null
If you assign values you will have to use the numbers: INSERT INTO tbl1 (name,ismember,retired) values ('john',0,-1);
3) The advantage of this method: you can use where clauses like this:
SELECT * FROM tbl WHERE ismember and not retired;
4) Another advantage: conversion from php boolean from and to mySQL boolean are simple
5) If you want to pack multiple boolean values into one byte or so to save storage you will have to do the packing and unpacking by yourself, otherwise mySQL uses 1 or 2 bytes (?) for each TINYINT field.
Please anyone correct me if i'm wrong.
Greetings
K.
ASHBeN wrote:
What's the equivalent data type for boolean (0/1, True/False) in mySQL?
From MySQL.pdf file
BOOL = "synonym for CHAR(1)."
confused
From manual.pdf file
BOOL = "synonym for TINYINT(1)."
aha! The old ver. used CHAR(1) but CHAR must be bigger than INT beacuse INT can just be 0-9!
=)