简体   繁体   English

MySQL错误:``字段列表''中的未知列``变量''

[英]Mysql error:Unknown column 'variable' in 'field list'

I have got this function that returns a constant..Here is my class and function: 我有返回常数的函数。这是我的类和函数:

class Backlinks extends GoogleSearch {
const ROBOTS_NOINDEX_NOFOLLOW = 606;

    function robotsNoIndexNoFollow(){
    $crawler = new Connection();
    $curl = $crawler -> setUrl($this->url) ->getDocument();
    if ($curl){
        $html = new simple_html_dom($curl);
        $robots = $html -> find("meta[name=robots]", 0);
        $html -> clear();
        unset ($crawler);
        if ($robots){
            $content = $robots -> getAttribute("content");
            $content = strtolower($content);
            if (substr_count($content, "noindex")){
                return ROBOTS_NOINDEX_NOFOLLOW; 
            }
            if (substr_count($content, "nofollow")){
                return ROBOTS_NOINDEX_NOFOLLOW;
            }
        }
        else{
            return false;
        }
    }

}

The problem above is in the ROBOTS_NOINDEX_NOFOLLOW contatnt. 上面的问题在ROBOTS_NOINDEX_NOFOLLOW冲突中。 The constant goes into another function as an error parameter to be updated in the database. 该常量作为错误参数进入另一个函数,在数据库中进行更新。

public function setStatus($error){
    $status = $error;
    if (!$error){
        $status = 200;
    }
    // only update the pages which weren't already scanned (for historic purposes).
    $query = "UPDATE task_pages tp 
        SET scan_status = $status 
        WHERE page_id = $this->pageID AND scan_status = 0";
    mysql_query($query) or die(mysql_error());
}

I get two errors: 我得到两个错误:

Notice: Use of undefined constant ROBOTS_NOINDEX_NOFOLLOW - assumed 'ROBOTS_NOINDEX_NOFOLLOW' in C:\\Program Files (x86)\\Zend\\Apache2\\htdocs\\backlinks\\cron\\Backlinks.php on line 78 Unknown column 'ROBOTS_NOINDEX_NOFOLLOW' in 'field list' 注意:使用未定义的常量ROBOTS_NOINDEX_NOFOLLOW-在第78行的C:\\ Program Files(x86)\\ Zend \\ Apache2 \\ htdocs \\ backlinks \\ cron \\ Backlinks.php中假定为'ROBOTS_NOINDEX_NOFOLLOW'。'字段列表'中的未知列'ROBOTS_NOINDEX_NOFOLLOW'

One is the problem with the constant not being defined..which I dont understand why. 一是没有定义常量的问题。我不明白为什么。 The second problem is with the sql..which interprets the constant as a column?!? 第二个问题是sql ..将常量解释为列吗?

Why and how to correct that? 为什么以及如何纠正?

You need qoutes around the string for MySQL to recognise it as data instead of a constant. 您需要在字符串周围使用qoutes,以便MySQL将其识别为数据而不是常量。 Try: 尝试:

"UPDATE task_pages tp 
        SET scan_status = '$status' 
        WHERE page_id = $this->pageID AND scan_status = 0";

You need to use 'self' to reference the constant: 您需要使用“自我”来引用常量:

return self::ROBOTS_NOINDEX_NOFOLLOW 返回自身:: ROBOTS_NOINDEX_NOFOLLOW

Otherwise, PHP would try to find the constant in the global scope even though in your case this is a class constant. 否则,即使您是一个类常量,PHP也会尝试在全局范围内查找该常量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM