php搜索数据库系统开发 php 搜索( 三 )


$dsn = "localhost";
$user = "sa";
$password = "";
//计算总记录数
$rs_num = "select count(*) as id from bbs where zu='0' and lei='".$lei."'";
$conn_id = odbc_connect($dsn,$user,$password);
$rnum = odbc_exec($conn_id,$rs_num);
while(odbc_fetch_row($rnum)){
$total_rs = odbc_result($rnum,"id");//将总记录数放入$total_rs变量
}
//计算与页有关的条数
$nnn = $total_rs / $show_num;//计算总页数
$hnnn = intval($nnn);//将总页数取整
$cnnnn = $nnn - $hnnn;
//计算所需总页数
switch ($cnnn){
case "0":
$hnnn++;
$nnn = $hnnn;//总页数
break;
default :
$nnn = $hnnn;//总页数
break;
};
if ($nnn == 0)$nnn++;
//计算页面改变所需的条件
$fore = $pages;
$next = $pages;
$fore -= 1;
$next += 1;
if ($fore0) {
echo "a首页/a";
echo "a前页/a";
};
if ($pages$nnn) {
echo "a后页/a";
echo "a尾页/a";
};
echo "共".$nnn."页";
$query_string = "SELECT * FROM table where condition order by you wanted order";
$cur = odbc_exec($conn_id,$query_string);
//取到循环的顶部
$cnum = ($pages-1) * $show_num;//计算当前的记录游标的位置
//空循环到显示记录游标处
if ($cnum != 0){
for ($i=0;$i=$cnum;odbc_fetch_row($cur)){$i++;};
};
$i=1;
//显示记录
while(odbc_fetch_row($cur)){
echo ;
if ($i == $show_num){//在不满页数时跳出程序
break;
};
$i++;
};
//关闭连接
odbc_close($conn_id);
?
Oracle(甲骨文)是世界上最为流行的关系数据库 。它是大公司推崇的工业化的强有力的引擎 。php搜索数据库系统开发我们先看看其相关的函数:
(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数据库插入数据的示例程序:
html
headtitle向ORACLE数据库中插入数据/title/head
body
form action="?echo $PHP_SELF;?" method="post"
table border="1" cellspacing="0" cellpadding="0"
tr
thID/th
thname/th
thDescription/th
/tr
tr
tdinput type="text" name="name" maxlength="50" size="10"/td
tdinput type="text" name="email" maxlength="255" size="30"/td
tdinput type="text" name="Description" maxlength="255" size="50"/td
/tr
tr align="center"
td colspan="3"input type="submit" value="https://www.04ip.com/post/提交"input type="reset" value="https://www.04ip.com/post/重写"/td
/tr
/table
/form
?
//先设置两个环境变量ORACLE_HOME,ORACLE_SID
putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");
putenv("ORACLE_SID=ora8");
//设置网页显示中文
putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");
if($connection=ora_logon("scott","tiger")) {
//库表test有ID,name,Description三项

推荐阅读