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

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数据库插入数据的示例程序:

 1<html>
 2<head><title>向ORACLE数据库中插入数据</title></head>
 3<body>
 4<form action="&lt;?echo $PHP_SELF;?&gt;" method="post">
 5<table border="1" cellpadding="0" cellspacing="0">
 6<tr>
 7<th>ID</th>
 8<th>name</th>
 9<th>Description</th>
10</tr>
11<tr>
12<td><input maxlength="50" name="name" size="10" type="text"/></td>
13<td><input maxlength="255" name="email" size="30" type="text"/></td>
14<td><input maxlength="255" name="Description" size="50" type="text"/></td>
15</tr>
16<tr align="center">
17<td colspan="3"><input type="submit" value="提交"/>  <input type="reset" value="重写"/></td>
18</tr>
19</table>
20</form>
21<?   
22  
23//先设置两个环境变量ORACLE_HOME,ORACLE_SID   
24  
25putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");   
26  
27putenv("ORACLE_SID=ora8");   
28  
29//设置网页显示中文   
30  
31putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");   
32  
33if($connection=ora_logon("scott","tiger")) {   
34  
35//库表test有ID,name,Description三项   
36  
37$sql = 'insert into test(ID,name,Description) values ';   
38  
39$sql .= '('' . $ID . '','' . $name . '',''. $Description . '')';   
40  
41if($cursor=ora_do($connect,$sql)) {   
42  
43print("insert finished!");   
44  
45}   
46  
47$query = 'select * from test';   
48  
49if($cursor=ora_do($connect,$query)) {   
50  
51ora_fetch($cursor);   
52  
53$content0=ora_getcolumn($cursor,0);   
54  
55$content1=ora_getcolumn($cursor,1);   
56  
57$content2=ora_getcolumn($cursor,2);   
58  
59print("$content0");   
60  
61print("$content1");   
62  
63print("$content2");   
64  
65ora_close($cursor);   
66  
67}   
68  
69ora_logoff($connection);   
70  
71}   
72  
73?>
74</body>
75</html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus