Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save yrsdi/d61109a2edc704be119ca25afc433be7 to your computer and use it in GitHub Desktop.

Select an option

Save yrsdi/d61109a2edc704be119ca25afc433be7 to your computer and use it in GitHub Desktop.
Execute stored procedure with BLOB parameter in PHP with OCI

Execute stored procedure with BLOB parameter in PHP with OCI

<?php
define('DB_USER','user1');
define('DB_PSWD','pswd1');
define('DB_CONN_STR','MYTNS');
define('DB_CHARSET','AL32UTF8');

$conn=oci_connect(DB_USER,DB_PSWD,DB_CONN_STR,DB_CHARSET);
$stmt=oci_parse($conn,'BEGIN MYPKG.MYPROC(:pBranch,:pUser,:pFile,:pContent); END;');
// prepare variables
$branch_code =978;
$user_id     =2037484758;
$filename    =$_FILES['file']['name'];
$tmp_filename=$_FILES['file']['tmp_name'];
// bind primitive parameters
oci_bind_by_name($stmt,':pBranch',$branch_code);
oci_bind_by_name($stmt,':pUser',$user_id);
oci_bind_by_name($stmt,':pFile',$filename);
// bind blob parameter
$blob=oci_new_descriptor($conn,OCI_DTYPE_LOB);
oci_bind_by_name($stmt,':pContent',$blob,-1,OCI_B_BLOB);
$bres=$blob->writetemporary(file_get_contents($tmp_filename));
// execute statement and commit changes
// specify OCI_NO_AUTO_COMMIT, otherwise you may get INVALID_OCI_HANDLE exception
$res=oci_execute($stmt,OCI_NO_AUTO_COMMIT);
oci_commit($conn);
// free resources and close connection
$blob->free();
oci_free_statement($stmt);
oci_close($conn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment