当前位置: 首页 > 图文教程 > 网络编程 > PHP > 不使用OCI8接口如何连接PHP和Oracle

PHP
PHP新手总结的PHP基础知识
php实现gb2312和unicode间编码转换
用php语言实现数据库连接详细代码介绍
详细解析 PHP 向 MySQL 发送数据过程
利用PHP V5开发多任务应用程序
详细讲解PHP中缓存技术的应用
php escapeshellcmd多字节编码漏洞
《PHP设计模式介绍》导言
《PHP设计模式介绍》第一章 编程惯用法
《PHP设计模式介绍》第二章 值对象模式
《PHP设计模式介绍》第三章 工厂模式
《PHP设计模式介绍》第四章 单件模式
《PHP设计模式介绍》第五章 注册模式
《PHP设计模式介绍》第六章 伪对象模式
《PHP设计模式介绍》第七章 策略模式
《PHP设计模式介绍》第八章 迭代器模式
《PHP设计模式介绍》第九章 观测模式
《PHP设计模式介绍》第十章 规范模式
《PHP设计模式介绍》第十一章 代理模式
《PHP设计模式介绍》第十二章 装饰器模式

不使用OCI8接口如何连接PHP和Oracle


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 212 ::
收藏到网摘: n/a

随着网站规模的扩大,MySql显然不能满足需求,在许多网站都
采用大型数据库Oracle的情况下,如何使用PHP来访问Oracle变的越发重要了。
我从我编写的一个简单iERP系统谈我自己是如何做的,在PHP官方手册里也有说明。
一般情况下或者说大多数人都是用Oracle8Call-Interface(OCI8)来连接数据库,
我这里介绍不使用OCI8接口而直接使用PHP的Oracle函数来连接数据库并处理数据。

注意:
php.ini配置中要去掉;extension=php_oracle.dll前的分号即
extension=php_oracle.dll

1,连接数据库

使用ora_logon()或者ora_plogon()来连接上数据库
ora_plogon功能与ora_logon类似,只不过ora_plogon开启与Oracle的长期连结
直至web服务停止

$handle=ora_plogon("system@localhost","manager")ordie;
"system@localhost"其中localhost是oracleSID名称,system是用户名称,manager是用户密码

2,打开游标
$cursor=ora_open($handle);

3,分析语法并执行指令
$query="selectcount(*)fromareawhereareacode='$addcode'";
ora_parse($cursor,$query)ordie;
ora_exec($cursor);

4,获取数据
if(ora_fetch($cursor))
$datacount=ora_getcolumn($cursor,0);
5,关闭游标
ora_close($cursor);

当然了你有可能执行的是delete或者insert语句不存在获取数据的步骤如:
INSERT:(插入)

$handle=ora_plogon("system@localhost","manager")ordie;
ora_commiton($handle);
$cursor=ora_open($handle);
$query="insertintoarea(areacode,areaname)values('$addcode','$addname')";
ora_parse($cursor,$query)ordie;
ora_exec($cursor);
ora_close($cursor);

DELETE:(删除)

$handle=ora_plogon("system@localhost","manager")ordie;
$cursor=ora_open($handle);
ora_commiton($handle);
$query="deletefromareawhereareacodein('222','444')";
ora_parse($cursor,$query)ordie;
ora_exec($cursor);
ora_close($cursor);