0

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); 

    if($result)
    {
        return true;
    }
    else
    {
        return false; 
    }
}`
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Sibusiso Shongwe
  • 176
  • 1
  • 2
  • 21

1 Answers1

0

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); 
Michail M.
  • 735
  • 5
  • 11