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
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query… The SQL statement executed was: INSERT INTO [dbo].[TUsers] ([userStatus], [userName], [userAddress], [userPhone], [userCategory], [userType], [userTabel], [userPassword]) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, :yp7)
can I set userPassword type to varbinary
ahmed201
(Rifajas)
January 7, 2014, 9:06am
2
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