PHP连接Oracle数据库的代码

$g_ora_session = 0;
$g_ora_db = 0;

// *******************************BEGIN CONFIGURATIONS************************************
define("G_ORA_LOGIN", "wsg_dblk@scdbdev");    // CONFIG for login and oracle instance name
define("G_ORA_PASSWORD", "wsg_dblk");       // CONFIG for password
define("G_ORA_ACCESS_ALL_TABLE", TRUE);      // CONFIG for allow access all table
define("G_ORA_HOME_ENV",
 "ORACLE_HOME=/oraexe/oracle/v8.1.7");      // CONFIG for Oracle HOME in Linux
//define("G_ORA_HOME_ENV",
//  "ORACLE_HOME=c:/orant");       // CONFIG for Oracle HOME in Windows
// ********************************END CONFIGURATIONS*************************************

// connect to oracle and open database
function open_oracle_db()
{
 global $g_ora_session;
 global $g_ora_db;
 
 if ((G_ORA_HOME_ENV != NULL) && (G_ORA_HOME_ENV != ""))
  putenv(G_ORA_HOME_ENV);  // CONFIG
 //PrintTrace("G_ORA_LOGIN = " . G_ORA_LOGIN);
 //PrintTrace("G_ORA_PASSWORD = " . G_ORA_PASSWORD);
 $g_ora_session = ora_logon(G_ORA_LOGIN , G_ORA_PASSWORD) or
  die(return_error(E_INTERNAL_SYSTEM_ERROR, "003"));
 $g_ora_db = ora_open($g_ora_session) or
  die(return_error(E_INTERNAL_SYSTEM_ERROR, "004"));
 ora_commitoff($g_ora_session);
 
 // set date format as yyyy-mm-dd
 ora_parse($g_ora_db, "ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
 ora_exec($g_ora_db);
 
 // allow access all table?
 if (TRUE == G_ORA_ACCESS_ALL_TABLE) {
  ora_parse($g_ora_db, "ALTER SESSION SET GLOBAL_NAMES=FALSE");
  ora_exec($g_ora_db);
 }
 
 return $g_ora_db;
}

// close database and disconnect oracle.
function close_oracle_db()
{
 global $g_ora_session;
 global $g_ora_db;
 
 if ($g_ora_db > 0)
 {
  ora_close($g_ora_db);
  ora_logoff($g_ora_session);
 }
 
 $g_ora_db = 0;
 $g_ora_session = 0;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值