[英]Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query
I'm using MySQL in development, storing base64 image in longblob
data type. 我在开发中使用MySQL,以longblob
数据类型存储base64图像。
But I'm getting error below when trying to insert data after I changed database to MS SQL & data type to varbinary(max)
但是在将数据库更改为MS SQL并将数据类型更改为varbinary(max)
后尝试插入数据时,出现以下错误
Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. 不允许从数据类型varchar(max)隐式转换为varbinary(max)。 Use the CONVERT function to run this query 使用CONVERT函数运行此查询
So I put a mutator to get this around as below, 所以我放了一个变幅器来解决这个问题,如下所示
public function setItemPictureAttribute($value)
{
$this->attributes['item_picture'] = DB::raw('CONVERT(VARBINARY(MAX), "'. $value .'")');
}
but I'm getting error below when trying to store the base64 image; 但是在尝试存储base64图像时出现以下错误;
The identifier that starts with '/9j/4QxnRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAMAAAExAAIAAAAeAAAAcgEyAAIAAAAUAAAAkIdp' is too long. 以'/ 9j / 4QxnRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAMAAAExAAIAAAAAAAAAAAAAgEyAAIAAAAUAAAAAAAkIdp'开头的标识符太长。 Maximum length is 128` 最大长度为128`
What did I miss? 我错过了什么?
EDIT: Somehow I got this work after I changed to $this->attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')");
编辑:在更改为$this->attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')");
之后,我以某种方式得到了这项工作$this->attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')");
; ; notice that I switched the double quote with single quote and vice versa in DB::raw
. 注意,我在DB::raw
中将双引号切换为单引号,反之亦然。 Maybe someone can explain why 也许有人可以解释为什么
Somehow I got this work after I changed to 我以某种方式获得这份工作后
$this->attributes['item_picture'] = DB::raw("CONVERT(VARBINARY(MAX), '". $value ."')");;
notice that I switched the double quote with single quote and vice versa in DB::raw
. 注意,我在DB::raw
中将双引号切换为单引号,反之亦然。 Maybe someone can explain why 也许有人可以解释为什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.