-1

So here is my problem.

I have a field in my database called maillist with the type tinyint(1). Using phpmyadmin i inserted into some fields the values 0's and 1's.
When i read from the database here is the array returned.

Array
(
    [User] => Array
        (
            [maillist] => 
        )

)

Where the maillist should be 0 or 1 because in my database all the fields on the maillist are filled.
So i decided to change the type on the field to tinyint(4) and that fixed the problem are here is the returned array.

Array
(
    [User] => Array
        (
            [maillist] => 0
        )

)

Please note that i did not change any values i just changed the type from tinyint(1) to tinyint(4).
Although the problem is fixed i would like to know what might have caused this behavior ? do i have a lack of understanding in retrieving data using cakephp ? Did i miss something important ? Or this might have been a bug.

Max Doumit
  • 1,065
  • 12
  • 33
  • 2
    mysql used to use tinyint(1) to simulate `bit` fields. When mysql finally added `bit` fields, some mysql drivers got confused by the new type and just made its values null, and did so by specifically checking for a `tinyint(1)`. – Marc B Dec 13 '12 at 21:35
  • Well it is not really of an overhead the difference between tinyint(4) and tinyint(1), so i will avoid the mess up and use tinyint(4), thank you loads for your reply! – Max Doumit Dec 13 '12 at 21:42
  • Marvan: really bad idea. the one will be interpreted as boolean, the other (your tinyint4) would be an integer. so please don't try to find your own wrong solution to a nonexistent problem. – mark Dec 13 '12 at 21:44
  • I am not interpreting it as boolean, here is what i am doing 'value' => $user['User']['maillist'] just to set the checked on a radio button, but i will keep that in mind. – Max Doumit Dec 13 '12 at 21:47
  • tinyint1 = boolean = 2 definite states. If you want to have more than two states (enumeration, list, ...) then you should use tinyint(2/3) or int(x). just for clarification. – mark Dec 13 '12 at 21:49

1 Answers1

2

Try var_dump($array) instead of pr($array)

pr() does not show variable types and will never show booleans as there is no true or false character.

http://codepad.viper-7.com/tUvSTu

dogmatic69
  • 7,574
  • 4
  • 31
  • 49
  • The problem was not in pr(), i only did used it to see the values returned. I was doing echo $user['User']['maillist'] and getting nothing. – Max Doumit Dec 13 '12 at 21:39
  • 1
    echo is the same as pr() / print_r(). You need to use var_dump() to see boolean types, especially false. Look at the paste. – dogmatic69 Dec 13 '12 at 21:42
  • 2
    or use `debug()` in cake >= 2.x this will show even false/true properly. – mark Dec 13 '12 at 21:43
  • 'maillist' => boolean false great ^^ i got your point ^^ And saw my mistake ! i want the value to be 1 or 0 to set the value of a radio button ! Thanks for your reply. – Max Doumit Dec 13 '12 at 21:48