I am attempting to upload a image to my database, i know it is bad practice to upload images to the database. I have it working by running the query in my php class (DB Handler). Now I am attempting to use a stored procedure and can't seem to find my error in my stored procedure. Apologies if my question seems vague.
数据库处理程序.php
public static function Business_Logo_Upload($image)
{
$sp = 'CALL uspBusines_Logo_Upload(?)';
return DBHelper::BlobUpload($sp,$image);
}
DBHelper.php
public static function BlobUpload($query,$image)
{
//Open Connection
$conn = DB::Connect();
//Prepare Query
$call = $conn->prepare($query);
$null = null;
$call->bind_param('b', $null);
$call->send_long_data(0, file_get_contents($image));
$call->execute();
//Close Connection
mysqli_close($conn);
//Return Result
return $call;
}
MYSQL存储过程
CREATE DEFINER=`BIT1`@`%` PROCEDURE `uspBusines_Logo_Upload`(IN logo LONGBLOB)
BEGIN
DECLARE errno INT;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
GET CURRENT DIAGNOSTICS CONDITION 1 errno = MYSQL_ERRNO;
SELECT errno AS MYSQL_ERROR;
ROLLBACK;
END;
START TRANSACTION;
SET autocommit=0;
UPDATE business
SET business.Logo = logo
WHERE business.BusinessID = 1;
END
最佳答案
CREATE DEFINER=`BIT1`@`%` PROCEDURE `uspBusines_Logo_Upload`(IN logo LONGBLOB)
BEGIN
UPDATE business
SET business.Logo = logo
WHERE business.BusinessID = 1;
END
This is the solution. Had to remove the transaction.
关于php - 使用存储过程、php和mysqli将图像/longblob上传到mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51762026/