Hi,everyone.I have a problem about active record boolean field.
My table schema sql is:
CREATE TABLE `foo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`isbar` bool NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
I have a Foo.php as:
class Foo extends CActiveRecord
{
public function rules()
{
return array(
array('isbar','boolean'),
);
}
}
I have a $fooObject which is an instance of Foo. let
$isbar=$fooObject->isbar;
$json=json_encode($isbar);
I found that $json is a string like "0" or "1",but what I need is 0 ,1 ,false or true.
In a word, how can I let boolean property return integer or boolean?
Page 1 of 1
Boolean Field Problem return string not integer
#2
Posted 07 December 2012 - 05:23 AM
Whenever I attempt to create a boolean field in InnoDB, it creates a field of type tinyint(1). I'd recommend changing your table schema to use that type, which should be recognised as an integer by PDO.
#3
Posted 07 December 2012 - 10:47 AM
Keith, on 07 December 2012 - 05:23 AM, said:
Whenever I attempt to create a boolean field in InnoDB, it creates a field of type tinyint(1). I'd recommend changing your table schema to use that type, which should be recognised as an integer by PDO.
I have tried tinyint(1),but nothing change.Actually,when I use bool in mysql,it creates a field of type tinyint(1) too. They are the same thing to mysql.
#4
Posted 07 December 2012 - 03:20 PM
Keith, on 07 December 2012 - 05:23 AM, said:
Whenever I attempt to create a boolean field in InnoDB, it creates a field of type tinyint(1). I'd recommend changing your table schema to use that type, which should be recognised as an integer by PDO.
Sorry!I misunderstood your meaning.After some researches,I knew this is a php 'bug'.
Now my question become:how to detect a field is tinyint(1) type in active record?
what is the correct api for something like $fooObject->metadata->columns["isbar"]->fieldtype==="boolean"?
Share this topic:
Page 1 of 1

Help












