-
☆ A M B ☆
- 24,524 Posts
dbtype is the database (MySQL? SQL Server?) data type, phptype is PHP's data type for the same data. They frequently aren't the same, and you can get some unexpected PHP output from not-quite-compatible data types. It's possible in PHP to use typecasting, but it's much better to tell xPDO what PHP data type you want and let MODx take care of any typecasting or conversion necessary.
As an example, using 0 as a boolean false in PHP can cause some hard-to-locate bugs, since 0 may be a perfectly good value, such as the (virtual) ID #0 the Tree root for a Wayfinder snippet call, or how many children a given resource has.
In MySQL, the 'boolean' type is an alias for TINYINT(1) and 0 is False while any non-0 value is True.
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
Some interesting things to know when using PHP booleans in the comments here.
http://www.php.net/manual/en/language.types.boolean.php
[ed. note: sottwell last edited this post 12 years, 9 months ago.]
-
☆ A M B ☆
- 24,524 Posts
The phptype would be boolean; the dbtype can also be boolean but it would internally (by MySQL, anyway, I don't know about MS SQL or any others) tinyint(1). Personally, since I'm thinking of it as a boolean I'd use boolean.
-
☆ A M B ☆
- 24,524 Posts
Well, that's how I would do it. Not sure about the precision, though, since internally MySQL is already thinking that from its interpretation of the boolean type, but I don't know a) if it's possible to leave it empty here, or b) if it's going to hurt anything by being there - I would presume that it won't hurt anything.
The modUser 'active' class is a boolean. It looks like this in the mysql schema:
<field key="active" dbtype="tinyint" precision="1" phptype="boolean" attributes="unsigned" null="false" default="1" />
-
☆ A M B ☆
- 24,524 Posts
I like to be contrary
I doubt if it really matters. I was just curious what one actually looked like.