首 页   · 站长博客 · 用户注册 · 会员登陆  · 会员排行  ·最新主题  ·最近回复  精华区  版权声明  ·论坛管理
  当前登录身份:游客,请先登录。  笔名: 口令: 验证码:   
楼 主  index »  PHP+MYSQL编程 » [求助]菜鸟求助:出错1064,不太理解症结所在,请大侠帮忙  


  作者:yang3123312
  注册时间:2005-06-28
  主题/回复:7/9
  积分:444
  等级:★★☆(五级)
  称号:略有小成

用户联系方式已设置为保密

 

 发表:2005-06-28 04:31:27 阅读 2825 次 回复 4 次 得分1  |   字号 字色
[求助]菜鸟求助:出错1064,不太理解症结所在,请大侠帮忙
我最近在试着做一个电子商务平台,在修改后台代码时出现如下错误:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #58' at line 1

select count(*) as total Resource id #58


我不明白到底是什么原因、该如何解决?在源代码中并未出现'Resource id #58' 阿。
我的开发环境是:php4.3+apache2.0+mysql 4.1
  
那位大侠知道的帮帮忙,谢谢啦!
 
 1#楼  
 
  回复人:一起PHP
  注册时间:2004-02-27
  主题/回复:247/1521
  积分:4649
  等级:★★★★★☆(十一级)
  称号:论坛圣人

   
 1#楼 发表于2005-06-28 16:36:13  评分:1 

源代码中没有出现现Resource id #58,但是可能有个变量的值是现'Resource id #58' 

你打开源代码搜索一下 “select count(*) as"
找到这个sql语句,看看里面是不是有的变量用错了。
 2#楼  
 
  回复人:yang3123312
  注册时间:2005-06-28
  主题/回复:7/9
  积分:444
  等级:★★☆(五级)
  称号:略有小成

用户联系方式已设置为保密
 2#楼 发表于2005-06-29 01:10:14  评分:× 

偶初来乍到,很感谢站长的回复!:)
我把代码翻来覆去的看了好久还是不得要领。站长能不能费心看看我的源代码呢?谢谢!
原文件中涉及到好几处有 select count(*) as total  ,为节省精力计我贴出下面这一段最有可能出错的部分:select count(*) 在line 34:
[php]
case 'delete_classification_confirm':
    if (isset($HTTP_POST_VARS['classification_id'])) {
  $classification_id = tep_db_prepare_input($HTTP_POST_VARS['classification_id']);

  $classification = tep_get_classification_tree($classification_id, '', '0', '', true);
  $customers = array();
  $customers_delete = array();

  for ($i=0, $n=sizeof($classification); $i<$n; $i++) {
    $customers_ids_query = tep_db_query("select customers_id from " . TABLE_CUSTOMERS_TO_CLASSIFICATION . " where classification_id = '" . (int)$classification[$i]['id'] . "'");

    while ($customers_ids = tep_db_fetch_array($customers_ids_query)) {
      $customers[$customers_ids['customers_id']]['classification'][] = $classification[$i]['id'];
    }
  }

  reset($customers);
  while (list($key, $value) = each($customers)) {
    $classification_ids = '';

    for ($i=0, $n=sizeof($value['classification']); $i<$n; $i++) {
      $classification_ids .= "'" . (int)$value['classification'][$i] . "', ";
    }
    $classification_ids = substr($classification_ids, 0, -2);

    $check_query = tep_db_query("select count(*) as total  from " . TABLE_CUSTOMERS_TO_CLASSIFICATION . " where customers_id = '" . (int)$key . "' and classification_id not in (" . $classification_ids . ")");
    $check = tep_db_fetch_array($check_query);
    if ($check['total'] < '1') {
      $customers_delete[$key] = $key;
    }
  }

// removing classification can be a lengthy process
  tep_set_time_limit(0);
  for ($i=0, $n=sizeof($classification); $i<$n; $i++) {
    tep_remove_classification($classification[$i]['id']);
  }

  reset($customers_delete);
  while (list($key) = each($customer_delete)) {
    tep_remove_customer($key);
  }
    }

    if (USE_CACHE == 'true') {
  tep_reset_cache_block('classification');
    
    }

    tep_redirect(tep_href_link(FILENAME_CUSTOMERS, 'ccPath=' . $ccPath));
    break;

其中tep_db_prepare_input、tep_get_classification_tree、tep_db_query、tep_db_fetch_array、tep_remove_classification、 tep_remove_customer、tep_reset_cache_block、tep_redirect 是自定义函数,TABLE_CUSTOMERS_TO_CLASSIFICATION 是一自建表,分别定义如下:
function tep_db_prepare_input($string) {
    if (is_string($string)) {
  return trim(stripslashes($string));
    } elseif (is_array($string)) {
  reset($string);
  while (list($key, $value) = each($string)) {
    $string[$key] = tep_db_prepare_input($value);
  }
  return $string;
    } else {
  return $string;
    }
  }


function tep_get_classification_tree($parent_id = '0', $spacing = '', $exclude = '', $classification_tree_array = '', $include_itself = false) {
    global $languages_id;

    if (!is_array($classification_tree_array)) $classification_tree_array = array();
    if ( (sizeof($classification_tree_array) < 1) && ($exclude != '0') ) $classification_tree_array[] = array('id' => '0', 'text' => TEXT_TOP);

    if ($include_itself) {
  $classification_query = tep_db_query("select cd.classification_name from " . TABLE_CUSTOMERS_CLASSIFICATION_DESCRIPTION . " cd where cd.language_id = '" . (int)$languages_id . "' and cd.classification_id = '" . (int)$parent_id . "'");
  $classification = tep_db_fetch_array($classification_query);
  $classification_tree_array[] = array('id' => $parent_id, 'text' => $classification['classification_name']);
    }

    $classification_query = tep_db_query("select c.classification_id, cd.classification_name, c.parent_id from " . TABLE_CUSTOMERS_CLASSIFICATION . " c, " . TABLE_CUSTOMERS_CLASSIFICATION_DESCRIPTION . " cd where c.classification_id = cd.classification_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' order by c.sort_order, cd.classification_name");
    while ($classification = tep_db_fetch_array($classification_query)) {
  if ($exclude != $classification['classification_id']) $classification_tree_array[] = array('id' => $classification['classification_id'], 'text' => $spacing . $classification['classification_name']);
  $classification_tree_array = tep_get_classification_tree($classification['classification_id'], $spacing . '   ', $exclude, $classification_tree_array);
    }

    return $classification_tree_array;
  }

 function tep_db_query($query, $link = 'db_link') {
    global $$link, $logger;

    if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
  if (!is_object($logger)) $logger = new logger;
  $logger->write($query, 'QUERY');
    }

    $result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());

    if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
  if (mysql_error()) $logger->write(mysql_error(), 'ERROR');
    }

    return $result;
  }

function tep_db_fetch_array($db_query) {
    return mysql_fetch_array($db_query, MYSQL_ASSOC);
  }

function tep_remove_classification($classification_id) {
    $classification_image_query = tep_db_query("select classification_image from " . TABLE_CUSTOMERS_CLASSIFICATION . " where classification_id = '" . (int)$classification_id . "'");
    $classification_image = tep_db_fetch_array($classification_image_query);

    $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_CUSTOMERS_CLASSIFICATION . " where classification_image = '" . tep_db_input($classification_image['classification_image']) . "'");
    $duplicate_image = tep_db_fetch_array($duplicate_image_query);

    if ($duplicate_image['total'] < 2) {
  if (file_exists(DIR_FS_CATALOG_IMAGES . $classification_image['classification_image'])) {
    @unlink(DIR_FS_CATALOG_IMAGES . $classification_image['classification_image']);
  }
    }

    tep_db_query("delete from " . TABLE_CUSTOMERS_CLASSIFICATION . " where classification_id = '" . (int)$classification_id . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_CLASSIFICATION_DESCRIPTION . " where classification_id = '" . (int)$classification_id . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_TO_CLASSIFICATION . " where classification_id = '" . (int)$classification_id . "'");

    if (USE_CACHE == 'true') {
  tep_reset_cache_block('classification');
  
    }
  }

function tep_remove_customer($customers_id) {
    

    tep_db_query("delete from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customers_id . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customers_id . "'");
    tep_db_query("delete from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customers_id . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_TO_CLASSIFICATION . " where customers_id = '" . (int)$customers_id . "'");
    tep_db_query("delete from " . TABLE_ORDERS . " where customers_id = '" . (int)$customers_id . "'");
    tep_db_query("delete from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customers . "'");
    tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customers . "'");
    tep_db_query("delete from " . TABLE_WHOS_ONLINE . " where customer_id = '" . (int)$customers_id . "'");

    $customers_reviews_query = tep_db_query("select reviews_id from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers_id . "'");
    while ($customers_reviews = tep_db_fetch_array($product_reviews_query)) {
  tep_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int)$customers_reviews['reviews_id'] . "'");
    }
    tep_db_query("delete from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers_id . "'");

    if (USE_CACHE == 'true') {
  tep_reset_cache_block('classifications');
 
    }
  }


 function tep_reset_cache_block($cache_block) {
    global $cache_blocks;

    for ($i=0, $n=sizeof($cache_blocks); $i<$n; $i++) {
  if ($cache_blocks[$i]['code'] == $cache_block) {
    if ($cache_blocks[$i]['multiple']) {
  if ($dir = @opendir(DIR_FS_CACHE)) {
    while ($cache_file = readdir($dir)) {
      $cached_file = $cache_blocks[$i]['file'];
      $languages = tep_get_languages();
      for ($j=0, $k=sizeof($languages); $j<$k; $j++) {
    $cached_file_unlink = ereg_replace('-language', '-' . $languages[$j]['directory'], $cached_file);
    if (ereg('^' . $cached_file_unlink, $cache_file)) {
      @unlink(DIR_FS_CACHE . $cache_file);
    }
      }
    }
    closedir($dir);
  }
    } else {
  $cached_file = $cache_blocks[$i]['file'];
  $languages = tep_get_languages();
  for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
    $cached_file = ereg_replace('-language', '-' . $languages[$i]['directory'], $cached_file);
    @unlink(DIR_FS_CACHE . $cached_file);
  }
    }
    break;
  }
    }
  }
[/php]


 3#楼  
 
  回复人:一起PHP
  注册时间:2004-02-27
  主题/回复:247/1521
  积分:4649
  等级:★★★★★☆(十一级)
  称号:论坛圣人

   
 3#楼 发表于2005-06-29 01:40:36  评分: 

代码比较复杂,一时看不太明白。

这个源程序的出处,可以查一下,是否有版本的要求。
因为从你的出错提示看,要么是SQL语句真有错误,要么是当前的MYSQL不支持这个SQL语句。

这个语句可以做两层理解,一、可能是一个嵌套查询,也就是从查询结果中再查询。因为Resurce #这样的东西,表示这个变量是一个资源型变量,不是普通的变量,而资源性变量就是mysql_query()返回的数据库查询结果。所以这个语句可能是一个从结果中查询的嵌套式查询语句。如果是这样的话,select count(*) from 后面跟一个资源型或许是对的,但是我没有试过。第二种可能就是这是代码的某个地方有笔误。比如$rs是一个资源型,而在写sql语句的时候不小心把某个语句写成了 select count(*) $rs。这样可能导致错误。

总之由于代码比较复杂,还是很难一下看出问题。得自己多加调试一下。
 4#楼  
 
  回复人:yang3123312
  注册时间:2005-06-28
  主题/回复:7/9
  积分:444
  等级:★★☆(五级)
  称号:略有小成

用户联系方式已设置为保密
 4#楼 发表于2005-06-29 03:26:28  评分:× 

好的,还是很感谢站长!长了很多见识!
我再反复调试调试。
  页数1/1首页 « 1 » 末页
  发表回复:您还没有登陆,无法发表回复。请先[登陆]

一起PHP技术联盟 主办:一起PHP 联系方式:站长QQ:4304410 QQ群:8423742 20159565 站长博客 E-mail: nqp@nqp.me 执行时间:0.045sec
SimsmaBBS 2008 (v6.0) Developed by 17php.com,Copyright(C)2003-2010 All rights reserved. 副本授权:一起PHP官方专用版