当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP调用三种数据库的方法(3)

PHP
连载3:利用PHP创建由Oracle驱动的SOAP服务
连载4:利用PHP创建由Oracle驱动的SOAP服务
理解Zend 框架 用PHP构建完美的阅读器
利用单元测试在每个层上对PHP代码进行检查
视频演示:Zend Platform功能特性详解
967个函式列表 PHP常用语法索引速查表
心得:PHP对文本数据库的五大基本操作方法
日记整理:Apache+MySql+PHP的快速安装
怎样才能成为PHP高手?学会"懒惰"的去编程
使用m17n实现对各国语言间的代码移植和转换
理解Zend 框架(1):构建完美的阅读器
理解Zend 框架(4): 用Zend_HTTP_Client 获取无提要的内容
ajax的最大缺点是什么?对搜索引擎的支持较弱
windows环境下mysql数据库的主从同步备份步骤
用AJAX实现聊天功能(part 1)
实例:用PHP实现Ftp用户的在线管理
利用PHP和CSS改变网页文字大小
PHP开发大型项目的方法[OOP思想]
直接读取数据库信息的三种方法
PHP5.3中新增的魔术常量__DIR__

PHP调用三种数据库的方法(3)


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

Oracle(甲骨文)是世界上最为流行的关系数据库。它是大公司推崇的工业化的强有力的引擎。我们先看看其相关的函数:

(1)integerora_logon(stringuser,stringpassword)

开始对一个Oracle数据库服务器的连接。

(2)integerora_open(integerconnection)

打开给出的连接的游标。

(3)integerora_do(integerconnection,stringquery)

在给出的连接上执行查询。PHP生成一个指示器,解析查询,并执行之。

(4)integerora_parse(integercursor,stringquery)

解析一个查询并准备好执行。

(5)booleanora_exec(integercursor)

执行一个先前由ora_parse函数解析过的查询。

(6)booleanora_fetch(integercursor)

此函数会使得一个执行过的查询中的行被取到指示器中。这使得您可以调用ora_getcolumn函数。

(7)stringora_getcolumn(integercursor,integercolumn)

返回当前的值。列由零开始的数字索引。

(8)booleanora_logoff(integerconnection)

断开对数据库服务器的链接。

以下是向ORACLE数据库插入数据的示例程序:

<html>

<head><title>向ORACLE数据库中插入数据</title></head>

<body>

<formaction="<?echo$PHP_SELF;?>"method="post">

<tableborder="1"cellspacing="0"cellpadding="0">

<tr>

<th>ID</th>

<th>name</th>

<th>Description</th>

</tr>

<tr>

<td><inputtype="text"name="name"maxlength="50"size="10"></td>

<td><inputtype="text"name="email"maxlength="255"size="30"></td>

<td><inputtype="text"name="Description"maxlength="255"size="50"></td>

</tr>

<tralign="center">

<tdcolspan="3"><inputtype="submit"value="提交">&nbsp;&nbsp;<inputtype="reset"value="重写"></td>

</tr>

</table>

</form>

<?

//先设置两个环境变量ORACLE_HOME,ORACLE_SID

putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");

putenv("ORACLE_SID=ora8");

//设置网页显示中文

putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");

if($connection=ora_logon("scott","tiger")){

//库表test有ID,name,Description三项

$sql='insertintotest(ID,name,Description)values';

$sql.='('.$ID.','.$name.','.$Description.')';

if($cursor=ora_do($connect,$sql)){

print("insertfinished!");

}

$query='select*fromtest';

if($cursor=ora_do($connect,$query)){

ora_fetch($cursor);

$content0=ora_getcolumn($cursor,0);

$content1=ora_getcolumn($cursor,1);

$content2=ora_getcolumn($cursor,2);

print("$content0");

print("$content1");

print("$content2");

ora_close($cursor);

}

ora_logoff($connection);

}

?>

</body>

</html>