Using PHP to access Oracle LOB in B/s structure

Source: Internet
Author: User
Tags bind file system php and requires stmt oracle database

Summary: This article describes how to use PHP's database access technology to implement the storage of Oracle LOB data objects.

Keywords: php;oracle; LOB; storage;

Introduction

PHP, or "Php:hypertext preprocessor", is a versatile scripting language that is widely used for open source and can be embedded in HTML. Its syntax is close to C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated Web pages quickly, but PHP's functionality is not limited to this. PHP is generally considered to be able to implement complex programming tasks faster and more efficiently, and it is because of its stability and the advantages of taking fewer resources to become the necessary web scripting language to develop B/s structure system, which plays a similar role in middleware, that is, syntax parsing and execution.

ORACLE LOB Data Model

In b/S (browser/server, browser/server) application system, need to store more than simply text information, but also include some pictures and audio-visual data or very long text. For example, the development of a set of official documents system, documents in the charts, attachments, such as binary files or extra long text will not be able to use ordinary characters or other types of data description, which requires the background database to store the ability of this data. This functionality is implemented using an Oracle LOB object.

An Oracle lob is a data type used to store large amounts of binary and textual data (a LOB field can store up to 4GB of data). Currently, it is divided into two categories: internal LOB and external lob. An internal LOB stores data as a stream of bytes inside the database. As a result, many of the internal LOB operations can participate in the transaction, or they can be backed up and restored like normal data. Oracle8i supports three types of internal lob:blob (binary data), CLOB (single-byte character data), NCLOB (multibyte country character data). Where the CLOB and NCLOB types apply to storing very long text data, blob word Zhi is used to store large amounts of binary data, such as images, video, audio, and so on. Currently, Oracle8i supports only one external LOB type, the bfile type. Within a database, the type stores only the location information of the data in the operating system, and the entity of the data exists in the file system of the operating system as an external file. Thus, the data represented by the type is read-only and does not participate in the transaction. This type can help users manage a large number of files accessed by external programs.

PHP Oracle 8 Function analysis

There are two sets of Oracle function extensions in PHP, where the ORACLE8 function allows access to the Oracle8 and Oracle7 databases, which use Oracle8 call-interface (OCI8) to bind local and global to the Oracle location identifier PHP variables that fully support LOB, FILE, and ROWID, allowing users to use user-defined variables, a custom object class for user databases.

Oracle8 function Ocifetchinto used to retrieve one row of data records into an array, the syntax of the function is described as follows:

int OCIFetchInto(array &result, int [mode])

Where the parameter mode can be omitted, the default value is Oci_num. If you want to return a LOB object when you access an Oracle LOB, mode should be set to Oci_assoc+oci_return_lobs.

The function ocibindbyname is used to bind a PHP variable to an Oracle object to establish data communication between PHP and Oracle, which is described as:

boolean OCIBindByName(int stmt, string ph_name, mixed &variable, int length, int [type])

The parameter stmt is a string index which is parsed by the Oracle analytic function Ociparse. Parameter ph_name is the name of the Oracle return variable that needs to be bound; variable must precede the & symbol, table PHP variable address. Parameter length is the length of the variable and, if set to-1, the maximum value of the specified variable variable is used; The parameter type can be omitted with a value of oci_b_file (binary file), Oci_b_cfile (text file), Oci_b_clob (text LOB), Oci_b_blob (bit LOB) and Oci_b_rowid (ROWID). It is noteworthy that the Ocinewdescriptor () function needs to be executed first, and the length parameter must be set to 1 when using the new data type specific to the Oracle8. Lob/rowid/bfile.

function Ocinewdescriptor is used to initialize a new lob/file description. The function syntax is described as:

string OCINewDescriptor(int connection , int [type])

Where the type is the same as the type definition in the Ocibindbyname function.

Required Environment Configuration

Using PHP's ORACLE8 function library requires Oracle8 client libraries. Before using this extension, make sure that you have set Oracle environment variables correctly for both Oracle users and Web daemon users. The environment variables you need to set are listed below:

Oracle_home #ORACLE安装路径

ORACLE_SID # Oracle Database ID

Ld_library_path #LD联接库路径

Nls_lang #ORALCE地区 (language) settings

ORA_NLS33 # ORA_NLS33 Path

The best way to verify that the above variables are correct in a Linux environment is to perform them separately under Oracle users and nobody:

# env

According to the output results, the above environment variables are judged to be consistent.

After setting the environment variables for the Web server user, you also need to add the Web server user (nobody, www) to the Oracle group.

For detailed instructions on ORACLE8 client and PHP installation settings, please refer to the relevant technical manuals.

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.