RE: [PHP-DB] Bit(1) datatype from mySQL
| From: | Bastien Koert | Date: | Sat, 07 Jan 2006 16:02:01 +0000 |
| Subject: | RE: [PHP-DB] Bit(1) datatype from mySQL | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-41002@lists.php.net to get a copy of this message | ||
You can cast it to a boolean (http://phpbuilder.com/manual/en/language.types.type-juggling.php#language.types.typecasting)
if (bool($IsAMember) == true) ...
bastien
From: Larry Bradley <lhbradley@igs.net> To: php-db@lists.php.net Subject: [PHP-DB] Bit(1) datatype from mySQL Date: Sat, 07 Jan 2006 09:45:42 -0500 Greetings: I'm new to PHP, although I've been a programmer all my life. I had been doing a bit of web database work with VB Script and ASP and mySQL, and then decided to try PHP. I've run into a couple of things that bother me. I have boolean fields (i.e. bit(1)) in the mySQL database. When I retrieve data from the mySQL server into an array or an object, it seems as if all the data fields are returned as characters. For most data types this does not matter, since PHP will handle them properly. This an integer 46 being retrieved as a character '46' is OK. However, the boolean is a curse, as it comes back as a character containing hex 00 or hex 01, and I have to use a test such as: if (ord(IsAMember) == 0) ... I can't just treat it as a boolean. I have got around the problem by using a construct such as: select if(IsAMember,1,0) as IsAMember in the SQL select, but this is a bit of a pain. Any thoughts? Thanks Larry Bradley Orleans (Ottawa), Ontario, CANADA -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php