4.3 显示结果
以下代码演示了怎样查询数据库并将结果输出:
function printoraerr($in_cur, $conn)
{
// 检查Oracle是否出错
// 如果存在错误则显示
// 当指针被激活时每次请求Oracle后调用该函数
// If it encountered an error, we exit immediately
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 "
\n";
for ($i=0;$i$w_numcols;$i++)
{
$align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";
echo "\t ".ora_columnname($cursor,$i)." \n";
}
echo "
\n";
while(ora_fetch($cursor))
{
echo " \n";
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)."
\n";
else
echo " ".ora_getcolumn($cursor,$i)." \n";
printoraerr($cursor,$conn);
}
$numrows++;
echo "
\n";
}
if ($numrows==0)
echo " Query returned no records
\n";
else
{
echo " \n";
echo " Count \n";
echo " $numrows \n";
echo "
\n";
}
echo " \n";
ora_close($cursor);
return;
}
// 主程序
if(!($conn=ora_logon("user@SID","password")))
{
echo "Error: Cannot connect to database\n";
exit;
}
$qry="SELECT
deptno \"Dept\"
,empno \"Emp\"
,empnm \"Name\"
,salary \"Salary\"
FROM
employee
ORDER BY 1,2";
exequery($qry);
ora_logoff($conn);
?
(译者注:以上代码段缺少注释,请读者参考PHP Manual的Oracle数据库函数部分)
4.4 基于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
\n";
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
\n";
exit;
}
}
?
求高人给一个用PHP+MySQL实现的简单的数据库查询功能的PHP和HTML代码首先php搜索数据库系统开发我是新手,看到这个问题试了下,不知道能不能帮助php搜索数据库系统开发你!希望~
还有很多条件没有判断,我正则不是很会 。写的很粗糙 , 勉强能用,希望别介意哈!
?php
class Database {
public $conn;
public function Database() {
$this-conn = mysql_connect("localhost","user","password");
mysql_select_db("gamesearch",$this-conn);
mysql_query("SET NAMES 'UTF8'");
}
public function get_data_array($sql) {
$rs = mysql_query($sql,$this-conn);
$data_array = array();
while($data = https://www.04ip.com/post/mysql_fetch_array($rs,MYSQL_ASSOC)) {
$data_array[] = $data;
}
mysql_free_result($rs);
return $data_array;
}
}
$db = new Database();
if($_GET['year'] == "") {
echo "请输入年份!";
}else {
推荐阅读
- 臻三环直播间的主播是谁,臻三环厂址
- 鸿蒙系统24小时在哪里调,鸿蒙系统在哪里升级
- 怎么把usb硬盘改成硬盘,怎么把usb硬盘改成硬盘启动
- 怎么用redis做测试,测试人员怎么测试redis
- mysql怎么扩容动态 mysql磁盘扩容
- 股票客户如何营销保险,股票营销话术技巧
- 竞技体育游戏联盟教案,竞技体育小游戏
- c语言退出函数怎么写 c语言退出系统代码
- 包含微信商城开通后怎么开通视频号的词条