How to connect PHP and Oracle without using the OCI8 interface

Source: Internet
Author: User
Tags insert interface connect php and query
Oracle

With the expansion of the site, MySQL is clearly unable to meet the demand, in many sites are
With large database Oracle, how to use PHP to access Oracle is becoming more important.
I've talked about how I did it from a simple ierp system I wrote, as explained in the official PHP manual.
In general or most people use Oracle8 call-interface (OCI8) to connect to a database,
Here I introduce Oracle functions that use PHP directly without using the OCI8 interface to connect to the database and process the data.
Attention:
PHP.ini configuration to be removed; the semicolon before Extension=php_oracle.dll is
Extension=php_oracle.dll

1, connecting to the database

Use Ora_logon () or Ora_plogon () to connect to the database
The Ora_plogon function is similar to Ora_logon, except that the Ora_plogon opens a long term connection with Oracle
Until the Web service stops

$handle = Ora_plogon ("System@localhost", "manager") or die;
"System@localhost" where localhost is the Oracle SID name, System is the user name, and the manager is the user password

2, open cursor
$cursor = Ora_open ($handle);

3, parsing grammar and executing instructions
$query = "SELECT count (*) from the area where AreaCode = ' $addcode '";
Ora_parse ($cursor, $query) or die;
Ora_exec ($cursor);

4, get the data
if (Ora_fetch ($cursor))
$datacount = Ora_getcolumn ($cursor, 0);
5, closing the cursor
Ora_close ($cursor);

Of course, you might be able to execute the DELETE or INSERT statement does not exist steps to get data such as:
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);




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.