Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp:插入tinyint字段时。“只得到”;0“;或;1“;_Php_Mysql_Cakephp - Fatal编程技术网

Cakephp:插入tinyint字段时。“只得到”;0“;或;1“;

Cakephp:插入tinyint字段时。“只得到”;0“;或;1“;,php,mysql,cakephp,Php,Mysql,Cakephp,我是cakephp的noob。从事开源项目。问题是: 当我为某个表插入一个值(“is_adjusted”(tinyint))时,我的php代码将成功执行。但该表只接受0或1作为其值。示例代码: $reward = $ta_customer_reward->newEntity(); $string_reward = var_export($reward, true); $reward->customer_email = $some_pre

我是cakephp的noob。从事开源项目。问题是:

当我为某个表插入一个值(“is_adjusted”(tinyint))时,我的php代码将成功执行。但该表只接受0或1作为其值。示例代码:

        $reward = $ta_customer_reward->newEntity();
        $string_reward = var_export($reward, true);
        $reward->customer_email = $some_preset_xyz;
        $reward->reward_amount = $some_preset_xyz;;
        $reward->particulars = $some_preset_xyz;
        .. .. .. 

        // This is_adjusted is the culprit.            
        $reward->is_adjusted = 2;

        $reward = $ta_customer_reward->save($reward);
现在,每当我在db中保存(插入)它时,它都存储为1。我被困了三天。我检查过的东西:

  • 未调整的默认值(以db为单位)

  • 没有其他函数覆盖该字段

  • ***1.奖品在我看来很不寻常。有一个属性名为dirty。我还在研究这个。但在我看来,现在它似乎是某种cakephp db对象结构

  • 这是CakePHPV3。xyz***

  • 这是CakePHP的设计。CakePHP总是将
    tinyint(1)
    视为布尔值,因此它总是将您的值转换为
    true
    /
    false
    ,因此
    1
    /
    0

    要解决此问题,请对列类型使用
    tinyint(2)
    。记住清除模型缓存


    CakePHP数据类型文档:

    关于此的博客帖子:


    类似的问答:

    事实上,tinyint(2)一直是人们应该用来制作的。谢谢Lionel Chan。你是个救生员。作为ckphp的noob,我一点也不知道框架可以推断出这样的事情。博客链接真的很有用。因为我的名声,我不能投票。但是非常感谢!!!别担心。如果你认为答案确实回答了你的问题,那就接受吧。