Hey, can any help me in a strange problem using PHP + Oracle.
I want upload a file to my DB in a blob field. See my code:

$lob = OCINewDescriptor($con,OCI_D_LOB);
$st2 = OCIParse($con,"UPDATE EMP SET EMP_LOGO = EMPTY_BLOB() WHERE emp_codigo = $emp_codigo returning EMP_LOGO INTO :EMP_LOGO");
OCIBindByName($st2,':EMP_LOGO',&$lob,-1,OCI_B_BLOB);
OCIExecute($st2);    
if($lob->savefile($logo))
    OCIcommit();

$logo is the file.

I get the error in the "$lob->savefile" line:

Warning: OCILobWrite: ORA-22990: LOB locators cannot span transactions in C:\Publico\Projetos_1\MOLWebSite\adm_em_co_salva.php on line 44

There is too few documentation about and I've tried all I could read. Now I gotta to ask you.

Thanks.

    OCIBindByName($st2,':EMP_LOGO',&$lob,-1,OCI_B_BLO😎;
    OCIExecute($st2);

    if($lob->savefile($logo))
    OCIcommit();

    the problem is not really a problem.
    use ociexecute($st2, OCI_DEFAULT);

    if you don't add the parameter OCI_DEFAULT, then
    ociexecute commits on success of this execution.
    but you want to comit later after saving the lob...

      Thank you Thomas. Have worked! 🙂
      But now I got another problem...
      I can't select the record. I already have tried all examples I could take in the net. The problem is that the descriptor seem not have the load method.

      My code:

      $row = OCINewDescriptor($conn,OCI_D_LOB); 
      $sql = OCIParse($conn,"SELECT EMP_LOGO INTO :EMP_LOGO FROM EMP WHERE EMP_CODIGO = '$emp_codigo'"); 
      OCIDefineByName($sql,"EMP_LOGO",&$row); 
      OCIExecute($sql, OCI_DEFAULT); 
      while (OCIFetchInto($sql, $row)) { 
      	$logo = $row["EMP_LOGO"]->load();
      }; 

      The error:

      Fatal error: Call to a member function on a non-object in adm_em_CO.php on line 35

      What do I do to PHP understand the load is a method of $row?

      Thank you the help!

        EMP_LOGO INTO :EMP_LOGO FROM EMP WHERE EMP_CODIGO = '$emp_codigo'");
        OCIDefineByName($sql,"EMP_LOGO",&$row);
        OCIExecute($sql, OCI_DEFAULT);
        while (OCIFetchInto($sql, $row)) {
        $logo = $row["EMP_LOGO"]->load();
        };


        the problem is the you have used INTO :EMP_LOGO,
        that means, that you have renamed the result column into :EMPLOGO

        remove INTO :EMP_LOGO from you sql query and it
        works.
        another hint:

        $logo=$row["EMP_LOGO"]->load();
        is better to write
        $logo=is_object($row["EMP_LOGO"]) ? $row["EMP_LOGO"]->load() : "";
        to prevent error messages....

        regards,
        tf

          Thank you the help, but I still getting the same error message. Need I make some bind from $row (the descriptor) with de SQL?

          To me appear the FetchInto is not returning anything in $row. But I am sure the record is in there.

          Can you give me any different perspective?

          Thanks a lot.

            oh yeah... you dont have to use
            ocifetchinto

            just write

            while(ocifetch($stmt)){
            $foo=$row->load();
            }

            you have $row a placeholder defined, where the
            content of the column is saved.

            there is no additional fetchinto nessesary.

              Done! 🙂))
              Thank you! It's all working.
              🙂

                Write a Reply...