SeanPONeil
SeanPONeil

Reputation: 3910

Identifier is too long when inserting a blob

I have an Oracle database that I am connecting to with PHP OCI8. One of my methods takes a Base64 Encoded image and decodes it and attempts to insert the image as a Blob. Oracle throws an the exception identifier is too long.

$query = "
    insert into field_call_photos (photo_datetime, field_call_visit_pk, photo, field_call_photo_type_pk)
    values (to_date('$visitDT  $visitDTHrs $visitDTMins $visitDTAmpm','mm/dd/yyyy hh:mi am'),
        '$newFcvPK', utl_encode.base64_decode(utl_raw.cast_to_raw($fileBlob)),'$fileTypePK')";

Upvotes: 1

Views: 1658

Answers (2)

mariofertc
mariofertc

Reputation: 421

Using Codeigniter connection, and fix the oci_commit where should be the connection id.

$db = $this->load->database('oracle', true);
$stmt = oci_parse($db->conn_id, "INSERT INTO LOTUS.PROCESO_ARCHIVO (ARCHIVO) VALUES(EMPTY_BLOB()) RETURNING archivo INTO :archivo");
$newlob = oci_new_descriptor($db->conn_id, OCI_D_LOB);
oci_bind_by_name($stmt, ":archivo", $newlob, -1, OCI_B_BLOB);
oci_execute($stmt,OCI_DEFAULT);        
$newlob->save(file_get_contents($file_path));
oci_commit($db->conn_id);
$newlob->free();
oci_free_statement($stmt);

Upvotes: 0

StasM
StasM

Reputation: 11062

You code seems to insert file content into the SQL query without quoting, which probably makes Oracle think it's an identifier.

I would use OCI blob functions instead. Something like this:

$stmt = oci_parse($database, "INSERT INTO (a,b,c, photo) VALUES('aval','bval','cval', EMPTY_BLOB()) RETURNING photo INTO :photo");
$newlob = oci_new_descriptor($database, OCI_D_LOB);
oci_bind_by_name($stmt, ":photo", $newlob, -1, OCI_B_BLOB);
oci_execute($stmt,OCI_DEFAULT);
$newlob->save(base64_decode($fileBlob));
oci_commit($stmt);
// cleanup
$newlob->free();
oci_free_statement($stmt);

I am omitting error checking for simplicity, you would need to check if the parse and the execute returned proper things and use oci_error to see what went wrong.

Upvotes: 2

Related Questions