我有一个返回constant..Here的函数,它是我的类和函数:
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());
}
我有两个错误:
注意:在C:\Program (x86)\Zend\Apache2\htdocs\backlinks\cron\Backlinks.php中使用未定义的常量ROBOTS_NOINDEX_NOFOLLOW --在‘字段列表’中的第78行未知列'ROBOTS_NOINDEX_NOFOLLOW‘中假定'ROBOTS_NOINDEX_NOFOLLOW’
一个是常数不是defined..which的问题,我不明白为什么。第二个问题是sql..which将常量解释为列?!?
为什么和如何纠正这一点?
发布于 2012-04-23 07:22:05
您需要使用“self”来引用常量:
返回self::ROBOTS_NOINDEX_NOFOLLOW
否则,PHP将试图在全局范围内找到常量,即使在您的例子中,这是一个类常量。
发布于 2012-04-23 07:20:42
您需要在字符串周围使用qoutes,以便MySQL将其识别为数据而不是常量。尝试:
"UPDATE task_pages tp
SET scan_status = '$status'
WHERE page_id = $this->pageID AND scan_status = 0";
https://stackoverflow.com/questions/10276332
复制相似问题