In PHP, store images in ORACLE. here is an example of using PHP to manipulate blob fields. I hope this will be helpful! <Br/> This example stores the uploaded image files in BLOB. here is an example of using PHP to manipulate the blob field. I hope it will be helpful!
This example stores the uploaded image files in BLOB.
Assume there is a table with the following structure:
Create table pictures (
Id number,
DESCRIPTION VARCHAR2 (100 ),
PICTURE BLOB
);
Then the PHP code is used to process data.
<〈? Php
// Establish an Oracle database connection
$ Conn = OCILogon ($ user, $ password, $ SID );
// Submit the SQL statement to Oracle
// Note the following two points: first, use the EMPTY_BLOB () function. This is an Oracle internal function that returns a LOB locator. When inserting a LOB, you can only use this method to generate an empty LOB locator and then operate on it. EMPTY_BLOB () function is for BLOB type, corresponding to CLOB is EMPTY_CLOB (). The second is the part after RETURNING, which returns picture so that php oci functions can handle it.
$ Stmt = OCIParse ($ conn, "insert into pictures (id, description, picture)
VALUES (pic_seq.NEXTVAL, '$ description', EMPTY_BLOB () RETURNING picture INTO: PICTURE ");
// Generate the descriptor of a local LOB object. Note the second parameter of the function: OCI_D_LOB, which indicates generating a LOB object. Other possibilities include OCI_D_FILE and OCI_D_ROWID, which correspond to BFILE and ROWID respectively.
$ Lob = OCINewDescriptor ($ conn, OCI_D_LOB );
// Bind the generated LOB object to the locator returned by the preceding SQL statement.
OCIBindByName ($ stmt, ': PICTURE', & $ lob,-1, OCI_ B _BLOB );
OCIExecute ($ stmt );
// Store data into the LOB object. Because the source data is a file, the LOB object's savefile () method is used directly. Other LOB object methods include save () and load (), which are used to save and retrieve data respectively. However, the BFILE type has only one method: save ()
If ($ lob-> savefile ($ lob_upload )){
OCICommit ($ conn );
Echo "uploaded successfully <br> 〉";
} Else {
Echo "Upload failed <br> 〉";
}
// Release the LOB object
OCIFreeDesc ($ lob );
OCIFreeStatement ($ stmt );
OCILogoff ($ conn );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.