PHP警告:mysql_num_rows()期望参数1是资源

时间:2012-11-05 07:05:51

标签: php mysql

PHP警告:mysql_num_rows()期望参数1是第x行的资源。 我检查了所有单引号丢失和sql链接。

$v = html_entity_decode($v);
            $query_1 = sprintf("select part_of_speech_id from word_parts_of_speech where word = '%s'", mysql_real_escape_string($v));
            $res = Commons::query($query_1) ;
            if(mysql_num_rows($res) != 0){
                    while  ($row  =  mysql_fetch_assoc($res))  {

                            if($row['part_of_speech_id']!=15){//see table down for reference

                                    $query_url = "insert into freetext_keywords(RANDOM_ID,URL,TAG_NAME,KEYWORD) values('$random_id','$url','$tagName','$v') on duplicate key update WEIGHT = WEIGHT + 1";
                                    $result = Commons::query($query_url);
                            }
                    }
            }else{
                    $query_url = "insert into freetext_keywords(RANDOM_ID,URL,TAG_NAME,KEYWORD) values('$random_id','$url','$tagName','$v') on duplicate key update WEIGHT = WEIGHT + 1";
                    $result = Commons::query($query_url);
            }


    }

1 个答案:

答案 0 :(得分:0)

只需在php中回显MySql查询并在phpmyadmin中对数据库运行(我希望你使用phpmyadmin访问你的数据库)

查看查询是否执行良好并返回结果。如果显示任何错误,请相应更正您的查询。

<?php

echo $query_1 = sprintf("select part_of_speech_id from word_parts_of_speech where word = '%s'", mysql_real_escape_string($v));

?>

从浏览器复制查询并直接针对数据库运行。