Home > Backend Development > PHP Tutorial > How to connect PHP and Oracle without using OCI8 interface_PHP tutorial

How to connect PHP and Oracle without using OCI8 interface_PHP tutorial

WBOY
Release: 2016-07-13 17:21:04
Original
799 people have browsed it


With the expansion of website scale, MySql obviously cannot meet the demand. With many websites
using large database Oracle, how to use PHP to access Oracle has become more and more important.
I will talk about how I did it from a simple iERP system I wrote, which is also explained in the official PHP manual.
Generally speaking, most people use Oracle8 Call-Interface (OCI8) to connect to the database.
Here I will introduce not using the OCI8 interface but directly using PHP's Oracle function to connect to the database and process data.

Note:
Remove the semicolon before ;extension=php_oracle.dll in the php.ini configuration, that is,
extension=php_oracle.dll

1, Connect to database

Use ora_logon() or ora_plogon() to connect to the database
ora_plogon function is similar to ora_logon, except that 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 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 be executing a delete or insert statement and there are no steps to obtain 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);


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532517.htmlTechArticleAs the scale of the website expands, MySql obviously cannot meet the demand. When many websites use large database Oracle , how to use PHP to access Oracle has become more and more important. I started with...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template