Model Types

Hi

I have userPassword column which varbinary(256) type in sql server database

I have created User model.




public function rules()

{

  return array(

	array('userName, userTabel, userAddress, userType, userCategory', 'required'),

	array('userName', 'length', 'max'=>255),

	array('userPassword', 'length', 'max'=>256),

  );

}



I wrote this code to my UserModel




protected function beforeSave() {

  $this->userPassword = md5($this->userPassword);

  $value = unpack('H*hex', $this->userPassword);

  $this->userPassword = '0x'.$value['hex'];

  return parent::beforeSave();

}



when I tried to save any user, it gives me this error

can I set userPassword type to varbinary

by analysing the above error stack trace. in the sql the your column is in nvarchar and it tries to convert to varbinary implicitly. so it tolds you to use CONVERT function to convert it to varbinary

yeah you right, but I converted the typed password to binary


protected function beforeSave() {

  $this->userPassword = md5($this->userPassword);

  $value = unpack('H*hex', $this->userPassword);

  $this->userPassword = '0x'.$value['hex'];

  return parent::beforeSave();

}

is there something like array(‘userPassord’,‘type’, ‘varBinary’, 255); or something in YII

thank you