


How to connect PHP and Oracle without using OCI8 interface_PHP tutorial
Jul 13, 2016 pm 05:21 PM
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);

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How to fix mysql_native_password not loaded errors on MySQL 8.4
