PHP Oracle 数据库函数库
要使用这个函数库,要在安装 PHP 及 Apache Server 之前先将 Oracle 数据库安装好,并确定 Oracle 能够顺利运作。之后在 PHP 配置 (configure) 时加入 --with-oracle=DIR 的选项,DIR 就是 $ORACLE_HOME 环境变量,例如:
./configure --with-oracle=/abc/def/oracle/product/7.0.3 --with-apache=../apache_1.3.x --enable-track-vars
以下的范例是
stevel@nettek-llc.com (22-Jan-1999) 所提供的。这个范例是返回 Oracle 中 sid1 数据库 (Database) 的 EMP 资料表 (Table) 所有资料。帐号是 SCOTT、密码为TIGER。
引用:
<?php
putenv ( "ORACLE_SID=sid1" );
putenv ( "ORACLE_HOME=/u01/app/oracle/product/8.0.5" );
$handle = ora_plogon ( "SCOTT@sid1" , "TIGER" ) or die;
$cursor = ora_open ( $handle );
ora_commitoff ( $handle );
$query = "SELECT * FROM EMP"
ora_parse ( $cursor , $query ) or die;
ora_exec ( $cursor );
echo "<HTML><PRE>n"
echo "$query nn "
$numcols = 0
while( ora_fetch ( $cursor )) {
$numcols = ora_numcols ( $cursor );
for ( $column = 0 $column < $numcols $column ++) {
$data = trim ( ora_getcolumn ( $cursor , $column ));
if( $data == "" ) $data = "NULL"
echo "$data t "
}
echo "n"
}
$numrows = ora_numrows ( $cursor );
echo " n ROWS RETURNED: $numrows n "
echo "</PRE></HTML>n"
ora_close ( $cursor );
?>