Hi everyone I have a sql server table that contains fields that are of type varbinary. The table model sees the field as a string, when it tries to save it it gives me the following error
SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Implicit conversion of data type from nvarchar to varbinary(max) is not allowed. To execute the query, use the CONVERT function.
I need to do this insert because I am saving files in the db, where they are already in varbinary format.
the rules of the
*/
public function rules()
{
return [
[['id_agenda'], 'integer'],
[['nota'],'string'],
[[ 'f_content', 'nome_file', 'uplfile', 'file'], 'string'],
[['nome_file', 'estensione'], 'required'],
[['descrizione'], 'string', 'max' => 200],
[['estenzione'], 'string', 'max' => 30],
];
the controller save
$model = new AgendaFiles();
if ($model->load(Yii::$app->request->post())){
print_R( (Yii::$app->request->post())) ;
$model->id_agenda=$_post['id_agenda'];
$model->file=UploadedFile::getInstance($model, 'file');
$model->nome_file=basename($model->file );
$model->estenzione=pathinfo($model->file ,PATHINFO_EXTENSION);
//$model->save();
$model->upload();
//$model->save();
$tmf='0x'.bin2hex(file_get_contents(Yii::getAlias('@webroot').'/uploads/'.
str_replace(' ', '_',$model->nome_file) ));
$model->f_content=$tmf;
if ($model->save(false)) {
echo 'save ';
}
else {
echo 'notsave';
}
any ideas? tks a lot!
solved using this code in the action