S.ninja S.ninja - 8 months ago 49
MySQL Question

how to pass a blob in php as a parameter and uploading it to a MySQL database?

I want to create a function that will receive values as parameters and upload them to a MySQL database. My problem is passing a blob to the function and uploading it to the database. My function currently looks like this:

public function addPost($id,$title,$description,$submitted_by,$screenshot)
$conn = $this->connect(); //connect to the database

$sql = "insert into complaint values('null','$title','$description',now(),'0000-00-0000:00:00.000000','$id','$status','$image','$screenshot')";
$result = mysqli_query($conn,$sql);

return true;
return false;


You can use these functions: base64_encode, base64_decode.
And just decoding and encoding blob value

for example:

$encode_image = base64_encode($image);
$sql = "insert into complaint values('null','$title','$description',now(),'0000-00-0000:00:00.000000','$id','$status','$encode_image','$screenshot')";
$result = mysqli_query($conn,$sql);