• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

PHP调用三种数据库的方法

发布: 2007-9-07 19:19 | 作者: Paladin | 来源: eNet论坛 | 查看: 12次 | 进入软件测试论坛讨论

领测软件测试网 相信大家对PHP已经很熟悉了。PHP内置了几乎对世界上所有的数据库的支持,而不再需要重新扩充。所以有人说:不会用PHP调用数据库,等于没学PHP。下面是笔者根据本人的操作经验和大侠们的意见而得出的总结,希望能给初学者提供一些益处。


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

(1)integer ora_logon(string user , string password)

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

(2)integer ora_open(integer connection)

打开给出的连接的游标。

(3)integer ora_do(integer connection, string query)

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

(4)integer ora_parse(integer cursor, string query)

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

(5)boolean ora_exec(integer cursor)

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

(6)boolean ora_fetch(integer cursor)

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

(7)string ora_getcolumn(integer cursor, integer column)

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

(8)boolean ora_logoff(integer connection)

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

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

〈html〉

〈head〉〈title〉向ORACLE数据库中插入数据〈/title〉〈/head〉

〈body〉

〈form action="〈?echo $PHP_SELF;?〉" method="post"〉

〈table border="1" cellspacing="0" cellpadding="0"〉

〈tr〉

〈th〉ID〈/th〉

〈th〉name〈/th〉

〈th〉Description〈/th〉

〈/tr〉

〈tr〉

〈td〉〈input type="text" name="name" maxlength="50" size="10"〉〈/td〉

〈td〉〈input type="text" name="email" maxlength="255" size="30"〉〈/td〉

〈td〉〈input type="text" name="Description" maxlength="255" size="50"〉〈/td〉

〈/tr〉

〈tr align="center"〉

〈td colspan="3"〉〈input type="submit" value="提交"〉 〈input type="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 = 'insert into test(ID,name,Description) values ';

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

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

print("insert finished!");

}

$query = 'select * from test';

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

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网