PHP连接Oracle数据库(2)

来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:34 点击:

if(ora_errorcode($in_cur))
{echo "Oracle code - ".ora_error($in_cur)." n";
ora_logoff($conn);
exit;
}
return;
}
function exequery($w_qry,$conn)
{
$cursor=ora_open($conn); printoraerr($cursor,$conn);
ora_parse($cursor,$w_qry,0); printoraerr($cursor,$conn);
ora_exec($cursor); printoraerr($cursor,$conn);
$numrows=0;
$w_numcols=ora_numcols($cursor);
// 显示头部
echo "
";
for ($i=0;$i<$w_numcols;$i++)
{
$align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";
echo "   ".ora_columnname($cursor,$i)."
";
}
echo "
";
while(ora_fetch($cursor))
{
echo "
";
for ($i=0;$i<$w_numcols;$i++)
{
$align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";
if(ora_columntype($cursor,$i)=="LONG")
echo " ".
ora_getcolumn($cursor,$i)."
";
else
echo " ".ora_getcolumn($cursor,$i)."
";
printoraerr($cursor,$conn);
}
$numrows++;
echo "
";
}
if ($numrows==0)
echo " Query returned no records
";
else
{
echo "
";
echo " Count
";
echo " $numrows
";
echo "
";
}
echo "
";
ora_close($cursor);
return;
}
// 主程序
if(!($conn=ora_logon("user@SID","password")))
{
echo "Error: Cannot connect to database
";
exit;
}
$qry="SELECT
deptno "Dept"
,empno "Emp"
,empnm "Name"
,salary "Salary"
FROM
employee
ORDER BY 1,2";
exequery($qry);
ora_logoff($conn);
?>


  基于HTTP的Oracle登录

  将以下代码加在PHP页面代码之前以确认Oracle登录。注意你必须正确设定$ SID。

if(!isset($PHP_AUTH_USER))
{
Header("WWW-authenticate: basic realm="$SID"");
Header("HTTP/1.0 401 Unauthorized");
$title="Login Instructions";
echo "
You are not authorized to enter the site
";
exit;
}
else
{
if (!($conn=ora_logon("$PHP_AUTH_USER@$SID",$PHP_AUTH_PW)))
{Header("WWW-authenticate: basic realm="$SID"");
Header("HTTP/1.0 401 Unauthorized");
$title="Login Instructions";
echo "
You are not authorised to enter the site
";
exit;
}}
?>

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Table函数使用简介
  • Oracle数据库Constraint约束的常用操作及异常处理
  • Bulk Collect性能分析(zz)
  • export/import的使用
  • OCP043第十五讲 Database Security
  • ORACLE10gr2数据导入MySQL方案
  • oracle 让sys用户可以使用isqlplus
  • 在oracle数据库下使用iSQL*Plus DBA访问数据库
  • Oracle行列转换小结
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1