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

PHP
MYSQL版本大于4.1问题 - PHPchina
怎么让用户点击一个连接后,把一个图片另存了 - PHPchina
武汉10月15日Phper聚会召集!!! - PHPchina
php如果不等待exec执行的程序创建的子进程? - PHPchina
哪位知道DISCUZ处理防SQL注入的代码是哪部分 - PHPchina
求教!我实在不知道哪里问题,在线等ing - PHPchina
怎样结束用户某一进程 - PHPchina
比对用户名密码能不能这样写? - PHPchina
求助:如何在PHP+mysql中实现数据备份? - PHPchina
大家看看这个配置对吗 - PHPchina
如何禁止require当前文件 - PHPchina
无法将回调函数放在类中? - PHPchina
村里 PHP代码高亮是怎么实现的? - PHPchina
apache安装后.服务里没有apache2这个服务! - PHPchina
请教一个小问题 - PHPchina
config.php里面是不是应该把多数参数设置为常量而不是变量? - PHPchina
请教高手一个问题 - PHPchina
如何让百度收录我的网站 ?? - PHPchina
谁能给个注入的简单语句? - PHPchina
求PHP站内搜索思路 - PHPchina

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 137 ::
收藏到网摘: 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);