1

I want to update image(blob) in my database using PHP. I was able to insert it successfully but unable to update it. I get 'invalid LOB locator specified' error.

This is insert query:

$myblobid = 157;

  // Insert the BLOB from PHP's tempory upload area

  $lob = oci_new_descriptor($db, OCI_D_LOB);
  $stmt = oci_parse($db, 'INSERT INTO JOB_SEEKER (SEEK_ID, SEEK_PICTURE) '
         .'VALUES(:MYBLOBID, EMPTY_BLOB()) RETURNING SEEK_PICTURE INTO :BLOBDATA');
  oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
  oci_bind_by_name($stmt, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
  oci_execute($stmt, OCI_DEFAULT);

  // The function $lob->savefile(...) reads from the uploaded file.
  // If the data was already in a PHP variable $myv, the
  // $lob->save($myv) function could be used instead.
  if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
    oci_commit($db);
  }
  else {
    echo "Couldn't upload Blob\n";
  }
  $lob->free();
  oci_free_statement($stmt);

I tried update query :

 $myblobid = 157;
      // Update 
      $lob = oci_new_descriptor($db, OCI_D_LOB);
      $stmt = oci_parse($db, 'UPDATE JOB_SEEKER SET SEEK_PICTURE = :BLOBDATA WHERE SEEK_ID = :MYBLOBID ');
      oci_bind_by_name($stmt, ':MYBLOBID', $myblobid);
      oci_bind_by_name($stmt, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
      oci_execute($stmt, OCI_DEFAULT);

      // The function $lob->savefile(...) reads from the uploaded file.
      // If the data was already in a PHP variable $myv, the
      // $lob->save($myv) function could be used instead.
      if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
        oci_commit($db);
      }
      else {
        echo "Couldn't upload Blob\n";
      }
      $lob->free();
      oci_free_statement($stmt);

1 Answer 1

1

This resolved my problem:

 $lob = oci_new_descriptor($db, OCI_D_LOB);
   $myblobid = 157;
  $stmt = oci_parse($db, "UPDATE JOB_SEEKER SET SEEK_PICTURE = EMPTY_BLOB() WHERE SEEK_ID = '$myblobid' RETURNING SEEK_PICTURE INTO :BLOBDATA");

  oci_bind_by_name($stmt, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
  oci_execute($stmt, OCI_DEFAULT);

  // The function $lob->savefile(...) reads from the uploaded file.
  // If the data was already in a PHP variable $myv, the
  // $lob->save($myv) function could be used instead.
  if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
    oci_commit($db);
  }
  else {
    echo "Couldn't upload Blob\n";
  }
  $lob->free();
  oci_free_statement($stmt);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.