在数据库中存储值的问题 [英] Problem in storing value in database

查看:108
本文介绍了在数据库中存储值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CakePHP框架与MySQL数据库,我有问题,保存一个特定的值到数据库。我有一个名为属性的表,包含字段,id,form_id,label,类型,大小和说明。单击链接时,默认值存储在这些字段的表中。

I am using CakePHP framework with MySQL database and I have problem in saving one particular value to the database. I have a table called 'Attributes' with fields,id,form_id,label,type,size and instructions. When a link is clicked,default values are stored in the table for these fields.

现在我在Attributes表中添加了一个名为'required'的新列。它的值为0或1,因此我最初将其创建为二进制字段。但是存储在它是\0。所以我把它改为整数值,并尝试保存一个默认值,如5,但是它存储的值总是0,即值不变。

Now I added a new column called 'required' to the Attributes table. Its value is either 0 or 1,so I initially created it as a binary field. But the stored in it was \0. So I changed it as integer value and tried to save a default value like 5. but the value stored in it is always 0,i.e.,the value doesn't change.

看起来很蠢,但我不知道原因。我给了下面的功能。所有其他字段的值将存储,除了必需字段。请有人帮助我

It seems silly,but I dont know the reason.I have given the function below. All the other field's value get stored except for the 'required' field. Please someone help me

   function saveFieldEntries($data)
   {	
      $this->data['Attribute']['form_id'] = $this->find('all', array(
    								'fields' => array('Form.id'),
    								'order' => 'Form.id DESC'
                                     ));
        $this->data['Attribute']['form_id']=$this->data['Attribute']['form_id'][0]['Form']['id'];

	    $this->data['Attribute']['label']= 'Label';
        $this->data['Attribute']['size']='50';
        $this->data['Attribute']['instructions']='Fill it';
        $this->data['Attribute']['type']=$data['Attribute']['type'];
        $this->data['Attribute']['sequence_no'] = $data['Attribute']['sequence_no'];
        $this->data['Attribute']['required']='5';
        $this->Attribute->save($this->data);
}


推荐答案

看起来很好。是否有可能你有一个缓存版本的模型,所以CakePHP仍然假设字段的类型是二进制?

At a glance, your code looks fine. Is it possible you've got a cached version of the model so CakePHP still assumes the field's type is binary?

尝试删除/ app / tmp / cache的内容/ models目录。

Try deleting the content of the /app/tmp/cache/models directory.

这篇关于在数据库中存储值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆