yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

ORA-22275: invalid LOB locator specified while inserting binary data #19

Closed rukiman closed 8 years ago

rukiman commented 9 years ago

Here is my PHP code: public function insertPacket($nist) { $blob = fopen($nist->getActualFile(), 'rb'); $sql = "INSERT INTO packets(packet) VALUES(:packet)"; $query = $this->link->prepare($sql); $query->bindParam(':packet', $blob, PDO::PARAM_LOB); if(!$query->execute()) {
trigger_error(print_r($query->errorInfo(), true), E_USER_ERROR);
} return $this->link->lastInsertId(); }

This works in MySQL. However using the pdo-via-oci8 I get this error: Fatal error: Uncaught exception 'Oci8Exception' with message ' in C:\wamp\www\project\includes\PdoViaOci8\Statement.php on line 156 Oci8Exception: Error Code : 22275 Error Message : ORA-22275: invalid LOB locator specified Position : 12 Statement : INSERT INTO packets(packet) VALUES(:packet) Bindings : [] Stack Trace : Array

Is inserting BLOB supported?

yajra commented 9 years ago

hi @rukiman , YES, inserting blob is supported. However, oracle have it's own implementation when saving a blob. See this link for ref: http://www.oracle.com/technetwork/articles/fuecks-lobs-095315.html. I will try to create an example on my free time.

yajra commented 9 years ago

@rukiman, sorry for very late response. Overlooked this one. Below is an example of how I insert a blob in laravel.

DB::transaction(function($conn){
    $pdo = DB::getPdo();
    $sql = "INSERT INTO mylobs (id, blobdata)
        VALUES (mylobs_id_seq.nextval, EMPTY_BLOB())
        RETURNING blobdata INTO :blob";
    $stmt = $pdo->prepare($sql);
    $stmt->bindParam(':blob', $lob, PDO::PARAM_LOB);
    $stmt->execute();
    $lob->save('blob content');
});

On your example, you need to add something like below after execute:

$blob->save(file_get_contents($nist->getActualFile()));
yajra commented 8 years ago

@rukiman, just to keep you posted, I have created a branch 1.0 and upcoming version 1.0 will now auto-save BLOB objects. Snippet like below should now work:

    $pdo = DB::getPdo();
    $sql = "INSERT INTO mylobs (id, blobdata)
        VALUES (mylobs_id_seq.nextval, EMPTY_BLOB())
        RETURNING blobdata INTO :blob";
    $stmt = $pdo->prepare($sql);
    $stmt->bindParam(':blob', $lob_long_content, PDO::PARAM_LOB);
    $stmt->execute();
yajra commented 8 years ago

If you can check if it works, then it is highly appreciated. Thanks!

yajra commented 8 years ago

Doing the proposed solution should fix the issue. Thanks!