MySQL does not have a boolean type.  For yes/no or true/false information, I
usually use an enumerator (enum) and define the "false" value first and the
"true" second.  (So "no" would be first and "yes" second.)  Then, when I
query for the value in that field, I can ask for it minus one, and I get a
numerical value that can be translated more easily into a boolean value,
where "false" is 0 and "true" is 1.  MySQL assigns the value of 1 to the
first element of the enumerator and reserves 0 for errors, so that's why you
have to subtract.  If you simply query for the value of the field, you will
get "false," "true," "no," "yes," or whatever -- but, if you put any
arithmetic operator into your SQL statement, MySQL will send you the results
of calculation using the numerical internal representation instead.

create table boolean_table(boolean enum("false","true"));
insert into boolean_table values("true"));

<?php
    $sql = "select boolean - 1 from boolean table";
    $r = mysql_query($sql, $link) or die("Cannot get result");
    $row = mysql_fetch_assoc($r);
    if ($row["boolean"])
        print "The value is true.\n";
?>

If I am working in C or PHP or another language that treats 0 as false and 1
as true, I can do this sort of test with the results -- or the reverse --
(this example is in C) --
if (!row[0])
    puts("The value is false.");

Amittai Aviram
[EMAIL PROTECTED]


----- Original Message -----
From: "Angelo Carmo" <[EMAIL PROTECTED]>
aTo: <[EMAIL PROTECTED]>
Sent: Tuesday, October 29, 2002 8:36 PM
Subject: access2mysql data types


>
> Hi people,
>
> what is the best type to substitute the boolean type of msaccess tables.
> Or mysql databases support the boolean type?
>
> Angelo.
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to