簡體   English   中英

MySQL錯誤:``字段列表''中的未知列``變量''

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

我有返回常數的函數。這是我的類和函數:

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;
        }
    }

}

上面的問題在ROBOTS_NOINDEX_NOFOLLOW沖突中。 該常量作為錯誤參數進入另一個函數,在數據庫中進行更新。

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());
}

我得到兩個錯誤:

注意:使用未定義的常量ROBOTS_NOINDEX_NOFOLLOW-在第78行的C:\\ Program Files(x86)\\ Zend \\ Apache2 \\ htdocs \\ backlinks \\ cron \\ Backlinks.php中假定為'ROBOTS_NOINDEX_NOFOLLOW'。'字段列表'中的未知列'ROBOTS_NOINDEX_NOFOLLOW'

一是沒有定義常量的問題。我不明白為什么。 第二個問題是sql ..將常量解釋為列嗎?

為什么以及如何糾正?

您需要在字符串周圍使用qoutes,以便MySQL將其識別為數據而不是常量。 嘗試:

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

您需要使用“自我”來引用常量:

返回自身:: ROBOTS_NOINDEX_NOFOLLOW

否則,即使您是一個類常量,PHP也會嘗試在全局范圍內查找該常量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM