[英]PHP convert base64 image string to blob for MySQL
I have the base64 string of an image in PHP, for example:我在PHP中有图片的base64字符串,例如:
$imgStr = 'data:image/png;base64,E0LdjA==';
I have a MySQL table with 2 fields id(varchar)
and img(blob)
.我有一个带有2个字段id(varchar)
和img(blob)
的MySQL表。 i have a stored procedure that inserts these values and is exceuted from PHP.我有一个存储过程,可以插入这些值,并从PHP中删除。
i used base64_decode($imgStr)
to convert the image to blob, the procedures executes but the value of blob in the Database is empty.我使用base64_decode($imgStr)
将图像转换为blob,该过程执行但数据库中blob的值为空。
here is my PHP function for the execution:这是我的PHP执行函数:
function test($id,$img){
if (connect()){
global $conn;
$query = $conn->prepare("CALL prctest(?,?,@rtn)");
$blob = base64_decode($img);
$query->bind_param('sb',$id,$blob);
$query->execute();
$result = $conn->query("SELECT @rtn as rtn");
$row = $result->fetch_assoc();
echo $row['rtn'];
$result->free();
close();
}
else{
echo "connection error!";
}
}
i cant figure out what wrong!我不知道怎么了!
I have the base64 string of an image in PHP, for example:我在PHP中有图片的base64字符串,例如:
$imgStr = 'data:image/png;base64,E0LdjA==';
I have a MySQL table with 2 fields id(varchar)
and img(blob)
.我有一个带有2个字段id(varchar)
和img(blob)
的MySQL表。 i have a stored procedure that inserts these values and is exceuted from PHP.我有一个存储过程,可以插入这些值,并从PHP中删除。
i used base64_decode($imgStr)
to convert the image to blob, the procedures executes but the value of blob in the Database is empty.我使用base64_decode($imgStr)
将图像转换为blob,该过程执行但数据库中blob的值为空。
here is my PHP function for the execution:这是我的PHP执行函数:
function test($id,$img){
if (connect()){
global $conn;
$query = $conn->prepare("CALL prctest(?,?,@rtn)");
$blob = base64_decode($img);
$query->bind_param('sb',$id,$blob);
$query->execute();
$result = $conn->query("SELECT @rtn as rtn");
$row = $result->fetch_assoc();
echo $row['rtn'];
$result->free();
close();
}
else{
echo "connection error!";
}
}
i cant figure out what wrong!我不知道怎么了!
I have the base64 string of an image in PHP, for example:我在PHP中有图片的base64字符串,例如:
$imgStr = 'data:image/png;base64,E0LdjA==';
I have a MySQL table with 2 fields id(varchar)
and img(blob)
.我有一个带有2个字段id(varchar)
和img(blob)
的MySQL表。 i have a stored procedure that inserts these values and is exceuted from PHP.我有一个存储过程,可以插入这些值,并从PHP中删除。
i used base64_decode($imgStr)
to convert the image to blob, the procedures executes but the value of blob in the Database is empty.我使用base64_decode($imgStr)
将图像转换为blob,该过程执行但数据库中blob的值为空。
here is my PHP function for the execution:这是我的PHP执行函数:
function test($id,$img){
if (connect()){
global $conn;
$query = $conn->prepare("CALL prctest(?,?,@rtn)");
$blob = base64_decode($img);
$query->bind_param('sb',$id,$blob);
$query->execute();
$result = $conn->query("SELECT @rtn as rtn");
$row = $result->fetch_assoc();
echo $row['rtn'];
$result->free();
close();
}
else{
echo "connection error!";
}
}
i cant figure out what wrong!我不知道怎么了!
I have the base64 string of an image in PHP, for example:我在PHP中有图片的base64字符串,例如:
$imgStr = 'data:image/png;base64,E0LdjA==';
I have a MySQL table with 2 fields id(varchar)
and img(blob)
.我有一个带有2个字段id(varchar)
和img(blob)
的MySQL表。 i have a stored procedure that inserts these values and is exceuted from PHP.我有一个存储过程,可以插入这些值,并从PHP中删除。
i used base64_decode($imgStr)
to convert the image to blob, the procedures executes but the value of blob in the Database is empty.我使用base64_decode($imgStr)
将图像转换为blob,该过程执行但数据库中blob的值为空。
here is my PHP function for the execution:这是我的PHP执行函数:
function test($id,$img){
if (connect()){
global $conn;
$query = $conn->prepare("CALL prctest(?,?,@rtn)");
$blob = base64_decode($img);
$query->bind_param('sb',$id,$blob);
$query->execute();
$result = $conn->query("SELECT @rtn as rtn");
$row = $result->fetch_assoc();
echo $row['rtn'];
$result->free();
close();
}
else{
echo "connection error!";
}
}
i cant figure out what wrong!我不知道怎么了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.