免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2257 | 回复: 8
打印 上一主题 下一主题

求教ADO连接Access数据库后的select写法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-20 11:41 |只看该作者 |倒序浏览
我发现ADO连接后的SQL语法的写法和标准的sql语法不太一样:

我的
select * from bmmc where user=\"$username\" and passwd=\"$passwd\"

在ADO语法中老是出错,
请问在ADO中应该怎么实现呢?

论坛徽章:
0
2 [报告]
发表于 2005-06-20 14:17 |只看该作者

求教ADO连接Access数据库后的select写法

这句应该不会错阿
是你的路径 搞错了吧?
下面是我的代码,可以执行,都用了好久了

论坛徽章:
0
3 [报告]
发表于 2005-06-20 14:25 |只看该作者

求教ADO连接Access数据库后的select写法


  1. <?php

  2. ?>;
  3. <!--METADATA TYPE="typelib"
  4. uuid="00000206-0000-0010-8000-00AA006D2EA4" -->;

  5. <HTML>;
  6.     <HEAD>;
  7.         <TITLE>;MultiScrolling Database Sample</TITLE>;
  8.     </HEAD>;

  9.         <BODY BGCOLOR="White" topmargin="10" leftmargin="10">;


  10.                 <!-- Display Header -->;

  11.                 <font size="4" face="Arial, Helvetica">;
  12.                 <b>;MultiScrolling Database Sample</b>;</font>;<br>;
  13.    
  14.                 <hr size="1" color="#000000">;

  15.                 Contacts within the Authors Database:<br>;<br>;

  16.                
  17.                 <?php

  18.                        
  19.                         // Map auth$oRs database to physical path
  20.                        


  21.                         // Create ADO Connection Component to connect with
  22.                         // sample database
  23.                         $oConn = new COM("ADODB.Connection");
  24.                         $co="DBQ=".realpath("./db1.mdb").";driver={microsoft access driver (*.mdb)};";
  25.                         $oConn->;Open($co);

  26.                        
  27.                         // Create ADO Recordset Component

  28.                         $oRs = new com("ADODB.Recordset");


  29.                         // Determine what PageNumber the scrolling currently is on

  30.                         $Mv = $_POST["Mv"];
  31.                         $PageNo = $_POST["PageNo"];


  32.                         if (!(($PageNo >; 0) || ($PageNo < 999)))
  33.                         {
  34.                                 $PageNo = 1;
  35.                         }

  36.                         // Setup Query Recordset (4 records per page)                       
  37.                         $oRs->;Open ("SELECT * FROM tab1", $oConn, 1);
  38.                         $oRs->;PageSize = 4;

  39.                        
  40.                         // Adjust PageNumber as Appropriate

  41.                         if ($Mv == "Page Up")
  42.                         {
  43.                                 if ($PageNo >; 1)
  44.                                 {
  45.                                         $PageNo--;
  46.                                 }
  47.                                 else
  48.                                 {
  49.                                         $PageNo = 1;
  50.                                 }
  51.                         }
  52.                         else if ($Mv == "Page Down")
  53.                         {
  54.                                 if ($oRs->;AbsolutePage < $oRs->;PageCount)
  55.                                 {
  56.                                         $PageNo++;
  57.                                 }
  58.                                 else
  59.                                 {
  60.                                         $PageNo = $oRs->;PageCount;
  61.                                 }
  62.                         }
  63.                         else
  64.                         {
  65.                                 $PageNo = 1;
  66.                         }

  67.                         $oRs->;AbsolutePage = $PageNo;
  68.                 ?>;

  69.                
  70.                 <!-- Draw Table of Contacts in DB -->;

  71.                 <TABLE BORDER=1>;
  72.                         <?php  for ($j = 0; $j < $oRs->;PageSize; $j++)
  73.                                 { ?>;
  74.                                 <TR>;
  75.                                 <?php
  76.                                         // Don't try to print the EOF record.
  77.                                         if ($oRs->;EOF)
  78.                                         {
  79.                                                 break;
  80.                                         } ?>;
  81.                                         <?php  for ($i = 0; $i < $oRs->;Fields->;Count; $i++)
  82.                                                 { ?>;       
  83.                                                 <TD VALIGN=TOP>;<?php echo  $oRs[$i] ?>;</TD>;
  84.                                         <?php  } ?>;
  85.                                 </TR>;

  86.                                 <?php
  87.                                         $oRs->;MoveNext();
  88.                                 }
  89.                                 ?>;
  90.                 </TABLE>;


  91.                 <!-- Scrolling Navigation Control for Sample -->;

  92.                 <Form Action="" Method="POST">;
  93.                         <Input Type="Hidden" Name="PageNo" Value="<?php echo $PageNo ?>;">;
  94.                         <!-- Only show appropriate buttons -->;
  95.                        
  96.                         <?php  if ($PageNo <  $oRs->;PageCount) { ?>;
  97.                                 <INPUT TYPE="Submit" Name="Mv" Value="Page Down">;
  98.                         <?php  } ?>;
  99.                        
  100.                         <?php  if ($PageNo >; 1) { ?>;
  101.                                 <INPUT TYPE="Submit" Name="Mv" Value="Page Up">;
  102.                         <?php  } ?>;
  103.                        

  104.                 </Form>;

  105.                 <?php
  106.                 $oRs->;close();
  107.                 $oConn->;close();
  108.                 ?>;

  109.         </BODY>;
  110. </HTML>;
复制代码

论坛徽章:
0
4 [报告]
发表于 2005-06-20 15:18 |只看该作者

求教ADO连接Access数据库后的select写法

我的代码:
原帖由 "kytexzy" 发表:

if ($BigClassID == 21 || $SmallClassID == 19) {
          $sql3  = "select name from bmmc where name={$username}";
    $rs3   = $conn->;Execute ($sql3);
    $user  = $rs3->;Fields(0);
         
          $row_count = 0;
          if (! $rs3->;EOF) {
                  $row_count ++;
                  $res = $rs3->;Fields(0);
                  echo $res->;value . " here <br>;";
                  //$rs3->;MoveNext ();
          }
          $num_rows = $row_count;
         
          $rs3->;Close ();
          $rs3->;Release ();
          $rs3 = null;
  }

错误提示:
Fatal error: Call to a member function on a non-object in D:\wz_new\news\read_news.php on line 75

75行是:
$sql3  = "select name from bmmc where name={$username}";
如果替换成:
$sql3  = "select name from bmmc";
就可以执行过去,我不知这个sql语句对查询怎么会有这种影响。

论坛徽章:
0
5 [报告]
发表于 2005-06-20 20:48 |只看该作者

求教ADO连接Access数据库后的select写法

  1. $sql3  = "select name from bmmc where name='".$username."'";
复制代码

这样写,试试

论坛徽章:
0
6 [报告]
发表于 2005-06-24 18:14 |只看该作者

求教ADO连接Access数据库后的select写法

用``把列表名包起来!就是TAB键上面那个键!

论坛徽章:
0
7 [报告]
发表于 2005-06-24 23:29 |只看该作者

求教ADO连接Access数据库后的select写法

都用了adodb了,还用这种古老的写法呀

论坛徽章:
0
8 [报告]
发表于 2005-06-27 10:59 |只看该作者

求教ADO连接Access数据库后的select写法

用adodb怎么写?请不吝赐教!

论坛徽章:
0
9 [报告]
发表于 2005-06-27 15:15 |只看该作者

求教ADO连接Access数据库后的select写法

楼主那样写不错才怪


$sql="select * from bmmc where user=$username and passwd=$passwd";
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP