PHP調(diào)用三種數(shù)據(jù)庫(kù)的方法(3)
更新時(shí)間:2006年10月09日 00:00:00 作者:
Oracle(甲骨文)是世界上最為流行的關(guān)系數(shù)據(jù)庫(kù)。它是大公司推崇的工業(yè)化的強(qiáng)有力的引擎。我們先看看其相關(guān)的函數(shù):
(1)integer ora_logon(string user , string password)
開(kāi)始對(duì)一個(gè)Oracle數(shù)據(jù)庫(kù)服務(wù)器的連接。
(2)integer ora_open(integer connection)
打開(kāi)給出的連接的游標(biāo)。
(3)integer ora_do(integer connection, string query)
在給出的連接上執(zhí)行查詢。PHP生成一個(gè)指示器,解析查詢,并執(zhí)行之。
(4)integer ora_parse(integer cursor, string query)
解析一個(gè)查詢并準(zhǔn)備好執(zhí)行。
(5)boolean ora_exec(integer cursor)
執(zhí)行一個(gè)先前由ora_parse函數(shù)解析過(guò)的查詢。
(6)boolean ora_fetch(integer cursor)
此函數(shù)會(huì)使得一個(gè)執(zhí)行過(guò)的查詢中的行被取到指示器中。這使得您可以調(diào)用ora_getcolumn函數(shù)。
(7)string ora_getcolumn(integer cursor, integer column)
返回當(dāng)前的值。列由零開(kāi)始的數(shù)字索引。
(8)boolean ora_logoff(integer connection)
斷開(kāi)對(duì)數(shù)據(jù)庫(kù)服務(wù)器的鏈接。
以下是向ORACLE數(shù)據(jù)庫(kù)插入數(shù)據(jù)的示例程序:
<html>
<head><title>向ORACLE數(shù)據(jù)庫(kù)中插入數(shù)據(jù)</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="重寫(xiě)"></td>
</tr>
</table>
</form>
<?
//先設(shè)置兩個(gè)環(huán)境變量ORACLE_HOME,ORACLE_SID
putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");
putenv("ORACLE_SID=ora8");
//設(shè)置網(wǎng)頁(yè)顯示中文
putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");
if($connection=ora_logon("scott","tiger")) {
//庫(kù)表test有ID,name,Description三項(xiàng)
$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>
(1)integer ora_logon(string user , string password)
開(kāi)始對(duì)一個(gè)Oracle數(shù)據(jù)庫(kù)服務(wù)器的連接。
(2)integer ora_open(integer connection)
打開(kāi)給出的連接的游標(biāo)。
(3)integer ora_do(integer connection, string query)
在給出的連接上執(zhí)行查詢。PHP生成一個(gè)指示器,解析查詢,并執(zhí)行之。
(4)integer ora_parse(integer cursor, string query)
解析一個(gè)查詢并準(zhǔn)備好執(zhí)行。
(5)boolean ora_exec(integer cursor)
執(zhí)行一個(gè)先前由ora_parse函數(shù)解析過(guò)的查詢。
(6)boolean ora_fetch(integer cursor)
此函數(shù)會(huì)使得一個(gè)執(zhí)行過(guò)的查詢中的行被取到指示器中。這使得您可以調(diào)用ora_getcolumn函數(shù)。
(7)string ora_getcolumn(integer cursor, integer column)
返回當(dāng)前的值。列由零開(kāi)始的數(shù)字索引。
(8)boolean ora_logoff(integer connection)
斷開(kāi)對(duì)數(shù)據(jù)庫(kù)服務(wù)器的鏈接。
以下是向ORACLE數(shù)據(jù)庫(kù)插入數(shù)據(jù)的示例程序:
<html>
<head><title>向ORACLE數(shù)據(jù)庫(kù)中插入數(shù)據(jù)</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="重寫(xiě)"></td>
</tr>
</table>
</form>
<?
//先設(shè)置兩個(gè)環(huán)境變量ORACLE_HOME,ORACLE_SID
putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");
putenv("ORACLE_SID=ora8");
//設(shè)置網(wǎng)頁(yè)顯示中文
putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");
if($connection=ora_logon("scott","tiger")) {
//庫(kù)表test有ID,name,Description三項(xiàng)
$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>
相關(guān)文章
使用數(shù)據(jù)庫(kù)保存session的方法
使用數(shù)據(jù)庫(kù)保存session的方法...2006-10-10PHP默認(rèn)安裝產(chǎn)生系統(tǒng)漏洞
PHP默認(rèn)安裝產(chǎn)生系統(tǒng)漏洞...2006-10-10php學(xué)習(xí)筆記之基礎(chǔ)知識(shí)
這篇文章主要介紹了php學(xué)習(xí)筆記的基礎(chǔ)知識(shí)部分,需要的朋友可以參考下2014-11-11