mysql_num_fields(): 提供的参数不是有效的 MySQL 结果资源 [英] mysql_num_fields(): supplied argument is not a valid MySQL result resource

查看:38
本文介绍了mysql_num_fields(): 提供的参数不是有效的 MySQL 结果资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自定义 CMS,对数据库架构和表示层进行了更改.使用以下代码部分时,我收到了与 mysql_num_fields 和 mysql_num_rows 相关的错误.有人可以告诉我为什么会出现这些错误吗?

I'm working on a custom CMS, made changes to the DB schema and presentation layer. I'm getting an error relative to mysql_num_fields and mysql_num_rows using the following section of code. Can someone give me an idea of why these errors are being raised?

public function viewTableData($db_name,$table_name,$fld01,$where_clause,$order_by,$asc_desc){

           mysql_select_db($db_name);

        if($fld01!="")
        {

            $sql = "Select $fld01 from $table_name";

        }
        else
        {

            $sql = "Select * from $table_name";

        }

        if($where_clause!="")
        {

            $sql=$sql." ".$where_clause;

        }

        if(($order_by!="")&&($asc_desc!=""))
        {

            $sql=$sql." ".$order_by." ".$asc_desc;

        }
        else if(($order_by!="")&&($asc_desc==""))
        {

            $sql=$sql." ".$order_by;

        }

        //return "<br/>sql  :".$sql;

        $result = mysql_query($sql);

        $count_fields = mysql_num_fields($result); 

        $count_rows = mysql_num_rows($result);

        if($count_rows>0)
        {
        $index = 0;

            unset($this->data_array);

          while ($row = mysql_fetch_assoc($result)) {

             $this->data_array[] = $row;

          } // while

    //Finally we release the database resource and return the multi-dimensional array containing all the data.

          mysql_free_result($result);

          return $this->data_array;
       }

    }

推荐答案

mysql_query 行之后添加一个 echo mysql_error(); 行以查看来自服务器的错误.

Slap an echo mysql_error(); line after the mysql_query line to see the error from the server.

这篇关于mysql_num_fields(): 提供的参数不是有效的 MySQL 结果资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆