<?php
  include("adodb/adodb.inc.php");
  $conn=&ADONewConnection('mysql');
  $conn->dabug=true;
  $conn->PConnect('localhost','root','123456','mydb');
  $sql="select * from user_data where id='1 '";
  $ar=$conn->Execute($sql);  
  if($ar){
  while($rs=$ar->FetchRow()){
 
 ?>
....
<?
}}
else {echo"Error!"}?>
在这段代码中,运行之后会出现Call to undefined method mysql_driver_ResultSet::FetchRow() in ...  
 出现问题的所在行:  while($rs=$ar->FetchRow()){
我做了一个测试,在  $ar=$conn->Execute($sql);  这一行的后面添加一句 echo $ar;   
则错误提示是:Object of class mysql_driver_ResultSet could not be converted to string in 
问题所在行就是新加上去的这句这里。请问这个是什么原因啊?如何解决?

解决方案 »

  1.   

    先检查数据库地址,用户名,密码和数据库名都对不对
    然后再检查select * from user_data where id='1 '对不对
    看上去这句有问题,最后的'1 '里有个空格
      

  2.   

    我做的一个测试,你自己改改吧。。<?php
    /*
     * Created on 2008-8-12
     *
     * To change the template for this generated file go to
     * Window - Preferences - PHPeclipse - PHP - Code Templates
     */
    header("Cache-Control: no-cache, must-revalidate");
    header("Content-Type: text/html; charset=utf-8");
     define('DIR_NAME','./');
     /*
     define('DBTYPE','mysql');
     define('DBNAME','cms');
     define('DBHOST','127.0.0.1');
     define('DBUSER','root');
     define('DBPASS','');
     define('DBPORT','');
     */
     $dbtype = 'mysql';
     $dbname = 'cms';
     $dbhost = '127.0.0.1';
     $dbuser = 'root';
     $dbpass = '';
     $dbport = '';
     
     include(DIR_NAME.'adodb/adodb.inc.php');
     include(DIR_NAME.'page.class.php');
     $db = NewADOConnection("$dbtype");
     $db-> Connect("$dbhost","$dbuser","$dbpass","$dbname");
     $db->Execute("set names utf8");
     //$db->debug = true;
     
     //sql
     //count all
       $pg = @$_REQUEST["pg"]; //接收当前的页码。
        $pagelist = 1; //设定每页显示10条记录
        $limitFrom = 0; //开始limit的数,用于当前pg(即页码)小于2的场合。此时sql的语句为..... limit 0,10
        if (!isset($pg))
    {                //如果接收的页码为空,说明当前为第一页。
             $pg = 0;    //把页码设定为第一页
        }
        if ($pg>1)
        { //当页码大于1 的时候,需要设定limitFrom。此时sql可能为 limit 30,10
             $limitFrom = $pagelist*($pg-1);    //这是个计算limitFrom小算法,仔细看看就能明白了。
        } else 
        {
             $limitFrom = 0;
        }
     $sqlcount = "select * from book";
     $result = &$db->Execute($sqlcount);
     $countAll = $result->RecordCount();//得出总记录数
     
     $sql = "select * from book";
     $db->SetFetchMode(ADODB_FETCH_ASSOC);
     $rs = &$db->SelectLimit($sql,$pagelist,$limitFrom); 
     //echo $sql;
    //$countAll = $rs->RecordCount()."<br>";
     if (!$rs)
     {
      echo $db->ErrorMsg();
     }
     else
     {
      while ($row = $rs->FetchNextObject())
      {
      echo $row->TITLE."<br>";
      //echo $row->CONTENT."<br>";
      }
     }
     $pager = new Pager($countAll,$pagelist);
     $action = $_GET['action'];
     
     if ($action == "insert")
     {
      $insert_sql = "insert into book" .
      "(uid,classid,title,content,addtime)" .
      "values(".
      "1,".
      "1,".
      "'测试一下标题',".
      "'测试一下内容',".
      "'".date("Y-m-d H:i:s")."'"
      .")";
      if (!($db->Execute($insert_sql)))
      {
      echo 'Error Inserting:'.$db->ErrorMsg();
      }
     }
     else if(!empty($action))
     {
      echo "other";
     }
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    ?>