LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1214|回复: 8

兄弟们有人帮忙进行ODBC连接吗

[复制链接]
发表于 2003-10-9 20:05:43 | 显示全部楼层 |阅读模式
哎,菜鸟一只了,以前将一个access修改成一个flash的网页,不喜欢IIS,现在已经可以进行ODBC连接了,可是对PHP生根不懂,有兄弟原意帮忙吗,谢谢
原先的ASP页面
http://dato.minidns.net/swf/php/flashasp1.htm
已经成功进行ODBC的页面
http://dato.minidns.net/swf/php/display.php
对数据库真是一窍不通,所以一次就把所有的数据都取出来了,晕好慢好慢
打包的源码,哪位帮忙修改
http://dato.minidns.net/tmp/php.rar
一个原先的HTML页面
http://dato.minidns.net/263/index.html
暑假
http://dato.minidns.net/263/flash/swf/fs000092.htm
 楼主| 发表于 2003-10-9 20:09:07 | 显示全部楼层
页面快照

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2003-10-9 20:11:44 | 显示全部楼层

ASP页面的display.asp

  1. <%Response.Buffer = true%><!--是否有必要-->
  2. <html>
  3. <head>
  4. <title>显示留言</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  6. <LINK href="00/style.css" rel=stylesheet>
  7. <STYLE type=text/css>TD {
  8.         COLOR: #000000; FONT-SIZE: 12px
  9. }
  10. A:active {
  11.         TEXT-DECORATION: none;COLOR: #ff9900
  12.         }
  13. A:hover {
  14.         TEXT-DECORATION: none;COLOR: #ff9900
  15. }
  16. A:link {
  17.         TEXT-DECORATION: none;COLOR: #ff9900
  18. }
  19. A:visited {
  20.         TEXT-DECORATION: none;COLOR: #ff9900
  21. }
  22. </STYLE>
  23. </head>
  24. <body  background="00/for2background.gif">
  25. <%
  26. '声明链接对象
  27. set dbconnection=server.createobject("adodb.connection")
  28. '设定与数据库的链接对象
  29. connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;data source="&server.mappath("swf.mdb")
  30. '打开数据库
  31. dbconnection.open connectionstring
  32. '创建command对象

  33. '声明Recorset对象,开始操作数据库
  34. set rs=server.createobject("adodb.recordset")

  35.   sql="select * from flash  order by pic desc"
  36.    rs.Open sql,dbconnection,1,1
  37.    if rs.EOF and rs.BOF then
  38.    Response.Write "<br><br><br><br><br><br><br><br><br><center><font size=5 color=red><b> 还 没 有 任 何 记 录!<br><font size=2>请点击,返回留言页面!</font><b></font>"
  39. %>
  40. <%Response.Write "</center><br><br><br><br><br><br>"
  41.    else
  42.    '设置分页显示属性

  43.      rs.PageSize=10
  44.      rs.AbsolutePage=1
  45.      if request("page")<>"" then  
  46.      rs.AbsolutePage=request("page")
  47.      end if
  48.    showtable
  49.    end if '设置分页显示
  50. sub showpages()
  51.     if rs.PageCount>=1 then
  52.       Response.Write "分页:"
  53.       for i=1 to rs.PageCount  
  54. %>
  55.                                  
  56. <%next                                       
  57.     end if                                       
  58. end sub                                       
  59. sub showtable                                       
  60. %>                                       
  61. <table border="0" cellPadding="0" cellSpacing="0" width="508">                                       
  62.   <%                                       
  63.        for i=1 to rs.PageSize                                       
  64.          if rs.EOF then                                       
  65.          exit for                                       
  66.          end if                                       
  67.            %>                                       
  68.   <tr>                                       
  69.     <td background="00/temp_05.gif" colSpan="5"><!--Start-->                                       
  70.       <table align="center" border="0" cellPadding="0" cellSpacing="0" width="95%">                                       
  71.         <tbody>                                       
  72.           <tr>                                       
  73.             <td vAlign="top" width="28%">      
  74.             <a href="fs.asp?page=<%=rs("pic")%>" target="_blank"><img border="1" height="60" src="images/<%=rs("pic")%>.gif" width="126"></a></td>                                       
  75.             <td vAlign="top" width="72%">                                       
  76.               <table border="0" cellPadding="0" cellSpacing="1" width="100%">                                       
  77.                 <tbody>                                       
  78.                   <tr>                                       
  79.                     <td bgcolor="#006600" width="64%"><font color="#ff9900">
  80. <a href="../<%=rs("source2")%>.swf"  style=cursor:text target="_blank"><%Response.Write Server.HTMLEncode(rs("title"))%></a></font></td>                                       
  81.                     <td bgcolor="#006600" width="36%"><font color="#ff9900">MTV<%=rs("type")%></font></td>                                       
  82.                   </tr>                                       
  83.                   <tr>                                       
  84.                     <td colSpan="2"><font color="#000000">作者:<%if rs("author")="" then                              
  85.              rsponse.write "none"                                    
  86.             else %>                              
  87. <%Response.Write Server.HTMLEncode(rs("author"))%><% end if %></font>                                                                 
  88.                  <font color="#000000">档案大小:<%if rs("size")="" then                                                                                            
  89.              rsponse.write "none"                                                                                       
  90.             else%>                                                                                    
  91. <%=rs("size")%><%end if%></font>                                                                                                                           
  92.                       Kb</td>                                                                                                                                 
  93.                   </tr>                                                                                                                        
  94.                   <tr>                                                                                                                        
  95.                     <td colSpan="2"><font color="#000000">演唱:<%if rs("singer")="" then                                                                                 
  96.              rsponse.write "none"                                                                                       
  97.             else%>                                                                                   
  98. <%Response.Write Server.HTMLEncode(rs("singer"))%><% end if %></font></td>                                                                                                                                 
  99.                   </tr>                                                                                                                        
  100.                   <tr>                                                                                                                        
  101.                     <td colSpan="2"><font color="#000000">档案简介:<%if rs("memo")="" then                                                                                 
  102.              rsponse.write "none"                                                                                      
  103.             else%>                                                                                 
  104. <%Response.Write Server.HTMLEncode(rs("memo"))%><%end if%></font></td>                                                                                                                                   
  105.                   </tr>                                                                                                                          
  106.                 </tbody>                                                                                                                          
  107.               </table>                                                                                                                          
  108.             </td>                                                                                                                          
  109.           </tr>                                                                                                                          
  110.         </tbody>                                                                                                                          
  111.       </table>                                                                                                                          
  112.     </td>                                                                                                                          
  113.   </tr>                                                                                                                          
  114. <%                                                                                                                        
  115. rs.movenext                                                                                                                        
  116. next%>                                                                                                                          
  117. </table>                                                                                                                  
  118. <%                                                                                                                  
  119. end sub                                                                                                                  
  120. %> <iframe src=00/forswf.htm width=507 height=46 scrolling=no frameborder=0></iframe>                                                                                                                        
  121. </body>                                                                                                                          
  122. </html>                                                                                                                          
  123.                                                                                                                           
复制代码
 楼主| 发表于 2003-10-9 20:13:40 | 显示全部楼层

可以成功连接的PHP页面display.php

[PHP]<html>
<head>
<title>显示留言</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="00/style.css" rel=stylesheet>
<STYLE type=text/css>TD {
        COLOR: #000000; FONT-SIZE: 12px
}
A:active {
        TEXT-DECORATION: none;COLOR: #ff9900
        }
A:hover {
        TEXT-DECORATION: none;COLOR: #ff9900
}
A:link {
        TEXT-DECORATION: none;COLOR: #ff9900
}
A:visited {
        TEXT-DECORATION: none;COLOR: #ff9900
}
</STYLE>
</head>
<body  background="00/for2background.gif">
                                      
   <?
        //连接到ODBC数据库
        $myconn=odbc_pconnect("swf.mdb","","");
        $strSql="select * from flash order by pic desc ";
        /*执行查询*/
        $result=odbc_do($myconn,$strSql);
        //Boolean odbc_fetch_row(integer result,integer row)
        while(odbc_fetch_row($result)==1)//通过循环读取数据内容
        {
?>
<table border="0" cellPadding="0" cellSpacing="0" width="508">  
  <tr>                                       
    <td background="00/temp_05.gif" colSpan="5"><!--Start-->                                       
      <table align="center" border="0" cellPadding="0" cellSpacing="0" width="95%">                                       
        <tbody>                                       
          <tr>                                       
            <td vAlign="top" width="28%">      
            <a href=../<?echo odbc_result($result,8)?>.swf target="_blank"><img border="1" height="60" src="images/<?echo odbc_result($result,9)?>.gif" width="126"></a></td>                                       
            <td vAlign="top" width="72%">                                       
              <table border="0" cellPadding="0" cellSpacing="1" width="100%">                                       
                <tbody>                                       
                  <tr>                                       
                    <td bgcolor="#006600" width="64%"><font color="#ff9900">
<a href=../<?echo odbc_result($result,8)?>.swf  style=cursor:text target="_blank"><?echo odbc_result($result,2)?></a></font></td>                                       
                    <td bgcolor="#006600" width="36%"><font color="#ff9900">MTV<?echo odbc_result($result,7)?></font></td>                                       
                  </tr>                                       
                  <tr>                                       
                    <td colSpan="2"><font color="#000000">作者:<?echo odbc_result($result,3)?></font></td>  
                  </tr>                     
                  <tr>                     
                    <td colSpan="2"><font color="#000000">档案简介:<?echo odbc_result($result,6)?></font></td>
                  </tr>                     
                </tbody>                    
              </table>                  
            </td>               
          </tr>               
        </tbody>            
      </table>           
    </td>         
  </tr>  
  </table>     
  <?
}        //关闭对数据库的连接
odbc_close("$myconn");
?>     
<iframe src=00/forswf.htm width=507 height=46 scrolling=no frameborder=0></iframe>                                                                                                                        
</body>                                                                                                                          
</html>                                                                                                                          
                                                                                                                          

[/PHP]
 楼主| 发表于 2003-10-9 20:15:15 | 显示全部楼层
先贴上两个吧,关键是对PHP的分页不知道怎么写ODBC相关的检索也不知道怎么弄
发表于 2003-10-9 21:13:22 | 显示全部楼层
兄弟,相信很少有人会看完你这么多的话还能有思路的。
以后问问题的话,请简介一点。
图文并茂很好,但是也要考虑到读者的感受。
php分页的见下:

  1. $page_size:这个变量是每一页中的记录数.
  2. $total:这个变量存从数据库中得到的记录数.
  3. $pages:这个变量存被分了多少页;
  4. $page:这个变量存当前是第几页.
  5. $from:这个变量存从什么地方开始查找.

  6. ****************************************************************************
  7. <?php
  8. $page_size=15; //每一页中的记录数.
  9. $sql="select * from $tbn";
  10. $r_sql=mysql_query($sql) or die(mysql_error()."3<br>");
  11. $total=mysql_num_rows($r_sql);//得到数据库中一共有多少要的记录数
  12. $pages=intval($total/$page_size);//intval()取得整数.得到一共要分多少页.

  13. if($total%$page_size) $pages++; //如果只有一页就把页数变量赋值为1.

  14. if(empty($page)) { //为$page这个变量赋值
  15. $page=1;
  16. $from=0;
  17. }
  18. else {
  19. $from=$page*$page_size-$page_size;
  20. //从第一条记录开始查找.
  21. }

  22. $sql="select * from $tbn limit ".$from.",".$page_size;
  23. $res=mysql_query($sql) or die(mysql_error()."4<br>");

  24. $row_url=Array();
  25. $row_name=Array();
  26. $row_date=array();
  27. $row_pre=array();
  28. $row_aut=array();

  29. //赋值
  30. $i=0;
  31. while($row=mysql_fetch_array($res)){
  32. --------------------- $row_name[$i]=mysql_result($res,$i,'news_name');//主题
  33. --------------------- $row_url[$i]=mysql_result($res,$i,'url');//地址
  34. --------------------- $row_date[$i]=mysql_result($res,$i,'date');//日期
  35. --------------------- $row_pre[$i]=mysql_result($res,$i,'periodical');//期数
  36. --------------------- $row_aut[$i]=mysql_result($res,$i,'author');//作者
  37. echo ($row_name[$i]."<br>");
  38. $i++;

  39. }
  40. ?>

  41. //注意为下边变量$page赋值的方法.
  42. <?php
  43. $a1="<a href=syjyby_news.php?";
  44. if($page==1){
  45. echo("首页 上一页");
  46. }
  47. else{
  48. $p_back=$page-1;
  49. echo("$a1&page=1><font color=#ff0000>首页</font></a> $a1&page=$p_back><font color=#ff0000>上一页</font></a>");
  50. }

  51. if($page>=$pages){
  52. echo("下一页 尾页");
  53. }
  54. else{
  55. $p_front=$page+1;
  56. echo("$a1&page=$p_front><font color=#ff0000>下一页</font></a> $a1&page=$pages><font color=#ff0000>尾页</font></a>");
  57. }
  58. echo(" 第 ".$page." 页 ");
  59. echo ("共[$pages]页 ");
  60. ?>
复制代码


说了半天我还是不知道,你为什么要用odbc?
如果用mysql和php的话,我想不用通过odbc就可以开发了吧。
建议你到喜悦村(http://www.phpx.com/happy/)去看看相关资料,
再看看问题能不能解决。
 楼主| 发表于 2003-10-9 21:21:36 | 显示全部楼层

一个分页显示ODBC数据库记录的类

好的,谢谢,我也找到一个分类
http://class.gzrail.net/read.php?classid=165

将access转为mysql有些麻烦所以就只能用ODBC了,数据库的东西太神奇了


[PHP]<?php
/*********************************************
TViewPage v 1.0

分页显示Access数据库记录的类
与我上次发布的另一个分页显示mysql记录的类,使用方法基本一样。

作者:sharetop
E-mail:ycshowtop@21cn.com
时间:2000-9-6

本类没有提供显示记录的功能,只是分页读取记录至 Result二维数组中。
需在外部自定义数据显示格式。

本类提供打开数据库的功能。请先用Init()初始化数据库。

***********************************************/
class TViewPage {

var $Table; //表名
var $MaxLine; //每页显示行数
var $LinkID; //数据库连接号
var $Id; //分页参考字段

var $Offset; //记录偏移量
var $Total; //记录总数
var $Number; //本页读取的记录数
var $Result; //读出的结果

var $TPages; //总页数
var $CPages; //当前页数

var $Condition; //显示条件 如:where id='$id' order by id desc
var $PageQuery; //分页显示要传递的参数


//******构造函数*************
//参数:表名、最大行数、分页参考字段、偏移量
//分页参考字段请用一个自动编号字段

function TViewPage($TB,$ML,$ID,$OF=0){
$this->Table=$TB;
$this->MaxLine=$ML;
$this->Offset=$OF;
$this->Condition=" ";
$this->Id=$ID;
}

//********初始化数据库连接*************
//参数:DSN、用户名、密码

function Init($dsn,$usr,$pws){
$this->LinkID=odbc_connect($dsn,$usr,$pws);
}

//********设置显示条件*********
//如:where id='$id' order by id desc
//要求是字串,符合SQL语法(本字串将加在SQL语句后)

function SetCondition($s){
$this->Condition=$s;
}

//******设置传递参数************
// key参数名 value参数值
// 如:setpagequery("id",$id);如有多个参数要传递,可多次调用本函数。

function SetPageQuery($key,$value){
$tmp[key]=$key; $tmp[value]=$value;
$this->ageQuery[]=$tmp;
}

//********读取记录***************
// 主要工作函数,根据所给的条件从表中读取相应的记录
// 返回值是一个二维数组,Result[记录号][字段名]

function ReadList() {
$SQL="SELECT Count(*) AS total FROM ".$this->Table." ".$this->Condition;

$result=odbc_do($this->LinkID,$SQL) or die("执行SQL错误");
odbc_fetch_row($result);
$this->Total=odbc_result($result,'total');

if($this->Total>0) { //根据条件 Condition
$SQL="SELECT * FROM ".$this->Table." ".$this->Condition.
" WHERE ".$this->Id." BETWEEN ".$this->Offset." AND ".($this->Offset+$this->MaxLine);

$result=odbc_exec($this->LinkID,$SQL) or die("执行SQL错误");
//$this->Number=odbc_num_rows($result);
//因为odbc_num_rows()函数返回值总不正常,所以用另一方法

$num=odbc_num_fields($result);
$k=0;
while(odbc_fetch_row($result)) {
for($i=1;$i<=$num;$i++) {
$key=odbc_field_name($result,$i);
$tmp[$key]=odbc_result($result,$i);
}
$this->Result[]=$tmp;
$k++;
}
}
$this->Number=$k;
return $this->Result;
}

//**********显示页数*************
//显示当前页及总页数

function ThePage() {
$this->TPages=ceil($this->Total/$this->MaxLine);
$this->CPages=$this->Offset/$this->MaxLine+1;
echo "第".$this->CPages."页/共".$this->TPages."页";
}

//**********显示翻页按钮*************
//此函数要在ThePage()函数之后调用!!!
//显示首页、下页、上页、未页,并加上要传递的参数

function Page() {
$first=0;
$next=$this->Offset+$this->MaxLine;
$prev=$this->Offset-$this->MaxLine;
$last=($this->TPages-1)*$this->MaxLine;

$k=count($this->ageQuery);
$strQuery=""; //生成一个要传递参数字串
for($i=0;$i<$k;$i++){
$strQuery.="&".$this->ageQuery[$i][key]."=".$this->ageQuery[$i][value];
}

if($this->Offset>=$this->MaxLine)
echo "<A href=$PHP_SELF?offset=".$first.$strQuery.">首页</A>|";
if($prev>=0)
echo "<A href=$PHP_SELF?offset=".$prev.$strQuery.">上一页</A>|";
if($next<$this->Total)
echo "<A href=$PHP_SELF?offset=".$next.$strQuery.">下一页</A>|";
if($this->TPages!=0 && $this->CPages<$this->TPages)
echo "<A href=$PHP_SELF?offset=".$last.$strQuery.">末页</A>";
}

//******end class
}

?>
[/PHP]
 楼主| 发表于 2003-10-10 18:34:09 | 显示全部楼层
[PHP]$row_name[$i]=mysql_result($res,$i,'news_name');//主题
--------------------- $row_url[$i]=mysql_result($res,$i,'url');//地址
--------------------- $row_date[$i]=mysql_result($res,$i,'date');//日期
--------------------- $row_pre[$i]=mysql_result($res,$i,'periodical');//期数
--------------------- $row_aut[$i]=mysql_result($res,$i,'author');//作者

还有这句$sql="select * from $tbn limit ".$from.",".$page_size;

[/PHP]
http://dato.minidns.net/swf/php/new1.php
请问大侠这部分做什么用的,我的表见图,该如何相应修改,谢谢

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2003-10-10 18:59:46 | 显示全部楼层
HOHO还是不懂啊,该解决的都解决了,可是下一页调用不知道为什么无效
[PHP]                                    

<?php
$myconn=mysql_connect("localhost","","");
mysql_select_db("php",$myconn);
$page_size=15; //每一页中的记录数.
$sql="select * from flash order by pic desc";
$r_sql=mysql_query($sql) or die(mysql_error()."3<br>");
$total=mysql_num_rows($r_sql);//得到数据库中一共有多少要的记录数
$pages=intval($total/$page_size);//intval()取得整数.得到一共要分多少页.

if($total%$page_size) $pages++; //如果只有一页就把页数变量赋值为1.

if(empty($page)) { //为$page这个变量赋值
$page=1;
$from=0;
}
else {
$from=$page*$page_size-$page_size;
//从第一条记录开始查找.
}

$sql="select * from flash limit ".$from.",".$page_size;
$res=mysql_query($sql) or die(mysql_error()."4<br>");

$row_ID=Array();
$row_title=Array();
$row_author=array();
$row_singer=array();
$row_size=array();
$row_memo=Array();
$row_type=Array();
$row_source2=array();
$row_pic=array();

//赋值
$i=0;
while($row=mysql_fetch_array($res)){
$row_ID[$i]=mysql_result($res,$i,'ID');//主题
$row_title[$i]=mysql_result($res,$i,'title');//地址
$row_author[$i]=mysql_result($res,$i,'author');//日期
$row_singer[$i]=mysql_result($res,$i,'singer');//期数
$row_size[$i]=mysql_result($res,$i,'size');//作者
$row_memo[$i]=mysql_result($res,$i,'memo');//主题
$row_type[$i]=mysql_result($res,$i,'type');//地址
$row_source2[$i]=mysql_result($res,$i,'source2');//日期
$row_pic[$i]=mysql_result($res,$i,'pic');//期数
#echo ($row_pic[$i]."<br>");
$i++;
?>

<table border="0" cellPadding="0" cellSpacing="0" width="508">  
  <tr>                                       
    <td background="00/temp_05.gif" colSpan="5"><!--Start-->                                       
      <table align="center" border="0" cellPadding="0" cellSpacing="0" width="95%">                                       
        <tbody>                                       
          <tr>                                       
            <td vAlign="top" width="28%">      
            <a href=../<?echo $row["source2"]?>.swf target="_blank"><img border="1" height="60" src="images/<?echo $row["pic"]?>.gif" width="126"></a>.
.
.
.
.
.
  </table>  
   <?
}

mysql_close($myconn);
?>  
<?php
$a1="<a href=new1.php?";
if($page==1){
echo("首页 上一页");
}
else{
$p_back=$page-1;
echo("$a1&page=1><font color=#ff0000>首页</font></a> $a1&page=$p_back><font color=#ff0000>上一页</font></a>");
}

if($page>=$pages){
echo("下一页 尾页");
}
else{
$p_front=$page+1;
echo("$a1&page=$p_front><font color=#ff0000>下一页</font></a> $a1&page=$pages><font color=#ff0000>尾页</font></a>");
}
echo(" 第 ".$page." 页 ");
echo ("共[$pages]页 ");
?>                           
</body>                                   
</html>  [/PHP]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表