How to connect PHP and Oracle without using the OCI8 Interface

Source: Internet
Author: User


As the scale of the website expands, MySql obviously cannot meet the requirements.
When using a large database of Oracle, it becomes more important to use PHP to access Oracle.
I wrote a simple iERP system to talk about how I did it. It is also described in the official PHP manual.
Generally, most people use Oracle8 Call-Interface (OCI8) to connect to the database,
I will introduce how to connect to the database and process data directly using Oracle functions of PHP without using the OCI8 interface.

Note:
In the php. ini configuration, remove the semicolon before extension = php_oracle.dll.
Extension = php_oracle.dll

1. Connect to the database

Use ora_logon () or ora_plogon () to connect to the database
Ora_plogon is similar to ora_logon, except that ora_plogon enables long-term connection with Oracle.
Until the web service is stopped

$ Handle = ora_plogon ("system @ localhost", "manager") or die;
"System @ localhost", localhost is the oracle SID Name, system is the user name, and manager is the user password.

2. Open the cursor.
$ Cursor = ora_open ($ handle );

3. Analyze the syntax and execute the command
$ Query = "select count (*) from area where areacode = $ addcode ";
Ora_parse ($ cursor, $ query) or die;
Ora_exec ($ cursor );

4. Get Data
If (ora_fetch ($ cursor ))
$ Datacount = ora_getcolumn ($ cursor, 0 );
5. Close the cursor.
Ora_close ($ cursor );

Of course, you may execute the delete or insert statement without the steps for getting data, such:
INSERT :( INSERT)

$ Handle = ora_plogon ("system @ localhost", "manager") or die;
Ora_commiton ($ handle );
$ Cursor = ora_open ($ handle );
$ Query = "insert into area (areacode, areaname) values ($ addcode, $ addname )";
Ora_parse ($ cursor, $ query) or die;
Ora_exec ($ cursor );
Ora_close ($ cursor );

DELETE: (DELETE)

$ Handle = ora_plogon ("system @ localhost", "manager") or die;
$ Cursor = ora_open ($ handle );
Ora_commiton ($ handle );
$ Query = "delete from area where areacode in (222,444 )";
Ora_parse ($ cursor, $ query) or die;
Ora_exec ($ cursor );
Ora_close ($ cursor );


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.