PHP insert Oracle clob field processing problems

Source: Internet
Author: User
Tags mysql text
If you have been in contact with MySQL, you must be familiar with MySQL text and Blob. in MySQL, you can directly operate on text and blob. However, in Oracle, it regards lob as a special field and cannot perform operations directly-for example, it cannot be directly inserted into the lob field or like query.
Values cannot be directly inserted into the lob field using the insert statement. Generally, there are the following steps:
1. analyze an insert statement and return a lob descriptor.
2 Use OCI Functions Generate A local lob object
3. Bind the lob object to the lob descriptor.
4. Execute the insert statement
5. assign a value to the lob object
6. Release lob objects and SQL statement handles
/*
// (Tabel_name: article) DDL; // just for test;
// Create table article (ID number (11), content clob );
*/

// ---------- This is insert test ----------------------------------
$ Conn = @ ocilogon ("yourusername", "yourpassword", "yourdatabase ");

$ Stmt = @ ociparse ($ Conn, "insert into article values (1, empty_clob () returning content into: content ");
$ Clob = @ ocinewdescriptor ($ Conn, oci_d_lob );
Ocibindbyname ($ stmt, ': content', & $ clob,-1, oci_ B _clob );
If (! Ociexecute ($ stmt, oci_default) {print_r (ocierror ($ stmt ));}
If ($ clob-> Save ($ cont ))
{
Ocicommit ($ conn );
}
Else
{
Print_r (ocierror ($ stmt ));
}
// --------------- Insert end -----------------------------------------


// --------------- Select Start ---------------------------------------
$ SQL = "select content from article order by ID DESC ";
$ Stmt = @ ociparse ($ Conn, $ SQL );
@ Ociexecute ($ stmt, oci_default );
@ Ocifetchinto ($ stmt, & $ rows, oci_return_lobs );
Echo "<br> content is: \" ". $ rows [0]." \ "";

// --------------- Select end -----------------------------------------

Note: you must pay attention to the reserved keywords of Oracle during testing. ocierror is often used for errors.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.