Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 特定搜索查询出错_Php_Mysql - Fatal编程技术网

Php 特定搜索查询出错

Php 特定搜索查询出错,php,mysql,Php,Mysql,我有一个网站ongrounds.com,上面有一个搜索栏,每当我搜索“最佳”这个词时,它会产生以下错误 警告:您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解在第264行的/home2/onground/public_html/libs/extensions/ezSQL/MySQL/ez_sql_MySQL.php的第1行hotaru_posts(post_status=%s或post_status=%s)中使用“%s”附近作为相关性的正确语法 注意:尝试在第132行的/h

我有一个网站ongrounds.com,上面有一个搜索栏,每当我搜索“最佳”这个词时,它会产生以下错误

警告:您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解在第264行的/home2/onground/public_html/libs/extensions/ezSQL/MySQL/ez_sql_MySQL.php的第1行hotaru_posts(post_status=%s或post_status=%s)中使用“%s”附近作为相关性的正确语法

注意:尝试在第132行的
/home2/onground/public_html/content/plugins/bookmarking/libs/BookmarkingFunctions.php中获取非对象的属性

但是当我搜索除“best”之外的任何其他单词时,搜索插件工作正常,并显示结果。我不知道为什么它在“最佳”一词上出现错误。请帮忙

搜索插件代码:

class Search
{ /** *添加权限和注册搜索小部件 */ 公共函数安装插件($h) { //权限 $site_perms=$h->getDefaultPermissions('all'); 如果(!isset($site_perms['can_search']){ $perms['options']['can_search']=array('yes','no'); $perms['can_search']['default']='yes'; $h->updateDefaultPermissions($perms); }

    // widget
    $h->addWidget('search', 'search', '');  // plugin name, function name, optional arguments
} 

/**
 * Get search results
 */
public function theme_index_top($h)
{
    // Get page title
    if ($h->cage->get->keyExists('search')) { 
        $title = stripslashes(htmlentities($h->cage->get->sanitizeTags('search'),ENT_QUOTES,'UTF-8'));
        $h->pageTitle = make_name($title);
        $h->subPage = 'search';
        $h->pageType = 'list';
        $h->pageName = 'search';
    }
} 


/**
 * Displays "Search!" wherever the plugin hook is.
 */
public function search_box($h)
{
    $h->displayTemplate('search_box', 'search');
}


/**
 * Displays "Search!" wherever the plugin hook is.
 */
public function widget_search($h)
{
    $h->displayTemplate('search_box', 'search');
}


/**
 * Use the search terms to build a filter
 */
public function bookmarking_functions_preparelist($h, $vars)
{
    if ($h->cage->get->keyExists('search')) 
    {
        $return = $vars['return'];  // are we getting the count or the result set?
        $orig_search_terms = stripslashes($h->cage->get->sanitizeTags('search'));
        $search_terms = $orig_search_terms;

        if ($search_terms)
        {
            // fetch select, orderby and filter...
            $prepared_search = $this->prepareSearchFilter($h, $search_terms, $return);
            extract($prepared_search);

            $h->vars['orig_search'] = $orig_search_terms; // use this to re-fill the search box after a search

            $h->vars['orig_search_terms'] = $orig_search_terms; // used in the breadcrumbs function

            return true;    
        }
    }

    return false;    
}

/**
 * Prepare search filter
 */
public function prepareSearchFilter($h, $search, $return = 'posts')
{
    $search_terms = strtolower($search);
    $search_terms = explode(" ", $search_terms);
    $search_terms = array_iunique($search_terms);

    $search_terms_clean = '';
    $full_text = true; // Do a full text (better) search if all terms are longer than 3 characters
    foreach($search_terms as $search_term) {

        if ($this->isStopword($search_term)) {
            continue; // don't include this in $search_terms_clean
        }

        if (strlen(trim($search_term)) < 4) {
            $full_text = false;
        }

        $search_term = trim($h->db->escape($search_term));

        // if the urlencoded term contains a percent sign, we can't use a full text search
        if (strpos(urlencode($search_term), '%') !== false) {
            $full_text = false;
        }

        $search_terms_clean .= $search_term . " ";
    }

    // Undo the filter that limits results to either 'top', 'new' or archived (See submit.php -> sub_prepare_list())
    if (isset($h->vars['filter']['post_status = %s'])) { unset($h->vars['filter']['post_status = %s']); }
    if (isset($h->vars['filter']['post_archived = %s'])) { unset($h->vars['filter']['post_archived = %s']); }

    // filter to top or new stories only:
    $h->vars['filter']['(post_status = %s OR post_status = %s)'] = array('top', 'new');

    $select = ($return == 'count') ? "count(*) AS number " : "*";
    if ($full_text) {
        $h->vars['select'] = array($select . ", MATCH(post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s) AS relevance" => trim($search_terms_clean));
        $h->vars['orderby'] = "relevance DESC";
        $h->vars['filter']["MATCH (post_title, post_domain, post_url, post_content, post_tags) AGAINST (%s IN BOOLEAN MODE)"] = trim($search_terms_clean); 
    } else {
        $h->vars['select'] = $select;
        $h->vars['orderby'] = "post_date DESC";
        $h->vars['filter_vars'] = array();
        $where = $this->explodeSearch($h, 'post_title', $search_terms_clean) . " OR ";
        $where .= $this->explodeSearch($h, 'post_url', $search_terms_clean) . " OR ";
        $where .= $this->explodeSearch($h, 'post_content', $search_terms_clean);
        $where = '(' . $where . ')';
        $h->vars['filter'][$where] = $h->vars['filter_vars'];
    }

    $prepared_search = array('select' => $h->vars['select'], 'orderby' => $h->vars['orderby'], 'filter' => $h->vars['filter']);

    return $prepared_search;
}


/** Explode search for short words
 * 
 * @param string $column
 * @param string $search_terms
 * @return string (with " OR " stripped off the end)
 */
public function explodeSearch($h, $column, $search_terms)
{
    $query = '';

    foreach(explode(' ', trim($search_terms)) as $word){
        if ($word) {
            $query .= $column . " LIKE %s OR ";
            $search_term = urlencode(" " . trim($h->db->escape($word)) . " ");
            // escape all percent signs for use in LIKE query:
            $search_term = str_replace('%', '\%', $search_term);
            array_push($h->vars['filter_vars'], "%" . $search_term . "%");
        }
    }

    return substr($query, 0, -4);
}


/**
 * Is it a stopword?
 *
 *@return bool
 */
public function isStopword($word)
{
    $word_array = array();

     // list came from http://meta.wikimedia.org/wiki/MySQL_4.0.20_stop_word_list
    $stopwordlist = "things ii iii a able about above according accordingly across actually after afterwards again against ain't all allow allows almost alone along already also although always am among amongst an and another any anybody anyhow anyone anything anyway anyways anywhere apart appear appreciate appropriate are aren't around as aside ask asking associated at available away awfully be became because become becomes becoming been before beforehand behind being believe below beside besides best better between beyond both brief but by c'mon c's came can can't cannot cant cause causes certain certainly changes clearly co com come comes concerning consequently consider considering contain containing contains corresponding could couldn't course currently definitely described despite did didn't different do does doesn't doing don't done down downwards during each edu eg eight either else elsewhere enough entirely especially et etc even ever every everybody everyone everything everywhere ex exactly example except far few fifth first five followed following follows for former formerly forth four from further furthermore get gets getting given gives go goes going gone got gotten greetings had hadn't happens hardly has hasn't have haven't having he he's help hence her here here's hereafter hereby herein hereupon hers herself hi him himself his hither hopefully how howbeit however i'd i'll i'm i've ie if ignored immediate in inasmuch inc indeed indicate indicated indicates inner insofar instead into inward is isn't it it'd it'll it's its itself just keep keeps kept know knows known last lately later latter latterly least less lest let let's like liked likely little look looking looks ltd mainly many may maybe me mean meanwhile merely might more moreover most mostly much must my myself name namely nd near nearly necessary need needs neither never nevertheless new next nine no nobody non none noone nor normally not nothing novel now nowhere obviously of off often oh ok okay old on once one ones only onto or other others otherwise ought our ours ourselves out outside over overall own part particular particularly per perhaps placed please plus possible presumably probably provides que quite qv rather rd re really reasonably regarding regardless regards relatively respectively right said same saw say saying says second secondly see seeing seem seemed seeming seems seen self selves sensible sent serious seriously seven several shall she should shouldn't since six so some somebody somehow someone something sometime sometimes somewhat somewhere soon sorry specified specify specifying still sub such sup sure t's take taken tell tends th than thank thanks thanx that that's thats the their theirs them themselves then thence there there's thereafter thereby therefore therein theres thereupon these they they'd they'll they're they've think third this thorough thoroughly those though three through throughout thru thus to together too took toward towards tried tries truly try trying twice two un under unfortunately unless unlikely until unto up upon us use used useful uses using usually value various very via viz vs want wants was wasn't way we we'd we'll we're we've welcome well went were weren't what what's whatever when whence whenever where where's whereafter whereas whereby wherein whereupon wherever whether which while whither who who's whoever whole whom whose why will willing wish with within without won't wonder would would wouldn't yes yet you you'd you'll you're you've your yours yourself yourselves zero";

    $word_array = explode(' ', $stopwordlist);

    if (array_search($word, $word_array) == true) {
        return true;
    } else {
        return false;
    }
}


/**
 * Add RSS link to breadcrumbs
 */
public function breadcrumbs($h)
{
    if ($h->subPage != 'search') { return false; }

    $crumbs = "<a href='" . $h->url(array('search'=>urlencode($h->vars['orig_search_terms']))) . "'>\n";
    $crumbs .= $h->vars['orig_search_terms'] . "</a>\n ";

    return $crumbs . $h->rssBreadcrumbsLink('', array('search'=>urlencode($h->vars['orig_search_terms'])));
}


/**
 * If a search feed, set it up
 */
public function post_rss_feed($h)
{
//小部件
$h->addWidget('search','search','');//插件名称、函数名称、可选参数
} 
/**
*获取搜索结果
*/
公共功能主题索引顶部($h)
{
//获取页面标题
如果($h->cage->get->keyExists('search')){
$title=stripslashes(htmlentities($h->cage->get->sanitizeTags('search')、entu引号、'UTF-8');
$h->pageTitle=make_name($title);
$h->subPage='search';
$h->pageType='list';
$h->pageName='search';
}
} 
/**
*在插件挂钩所在的位置显示“搜索!”。
*/
公共功能搜索框($h)
{
$h->displayTemplate('search_box','search');
}
/**
*在插件挂钩所在的位置显示“搜索!”。
*/
公共功能小部件搜索($h)
{
$h->displayTemplate('search_box','search');
}
/**
*使用搜索词构建过滤器
*/
公共函数书签\u函数\u准备列表($h,$vars)
{
如果($h->cage->get->keyExists('search'))
{
$return=$vars['return'];//我们得到的是计数还是结果集?
$orig_search_terms=stripslashes($h->cage->get->sanitizeTags('search');
$search\u terms=$orig\u search\u terms;
如果($search\u terms)
{
//获取选择、排序依据和筛选器。。。
$prepared\u search=$this->preparesearch过滤器($h,$search\u terms,$return);
摘录(准备好的搜索);
$h->vars['orig\u search']=$orig\u search\u terms;//使用此选项在搜索后重新填充搜索框
$h->vars['orig\u search\u terms']=$orig\u search\u terms;//在breadcrumbs函数中使用
返回true;
}
}
返回false;
}
/**
*准备搜索筛选器
*/
公共函数prepareSearchFilter($h,$search,$return='posts')
{
$search\u terms=strtolower($search);
$search\u terms=分解(“,$search\u terms”);
$search\u terms=array\u iunique($search\u terms);
$search\u terms\u clean='';
$full_text=true;//如果所有术语都超过3个字符,请执行全文(更好)搜索
foreach($search\u terms作为$search\u term){
如果($this->isStopword($search\u term)){
继续;//不要在$search\u terms\u clean中包含此内容
}
if(strlen(trim($search_term))<4){
$full_text=false;
}
$search\u term=trim($h->db->escape($search\u term));
//如果URL编码的术语包含百分号,则无法使用全文搜索
if(strpos(urlencode($search_term),“%”)!==false){
$full_text=false;
}
$search\u terms\u clean.=$search\u term.“;
}
//撤消将结果限制为“top”、“new”或存档的筛选器(请参见submit.php->sub_prepare_list())
如果(设置($h->vars['filter']['post_status=%s']){unset($h->vars['filter']['post_status=%s']);}
如果(设置($h->vars['filter']['post\u archived=%s']){unset($h->vars['filter']['post\u archived=%s']);}
//仅筛选到顶部或新故事:
$h->vars['filter']['(post_status=%s或post_status=%s)]=数组('top','new');
$select=($return='count')?“count(*)作为数字”:“*”;
如果($全文){
$h->vars['select']=array($select.),将(%s)作为相关性“=>trim($search\u terms\u clean))(post\u title、post\u domain、post\u url、post\u内容、post\u标记)匹配;
$h->vars['orderby']=“相关性描述”;
$h->vars['filter'][“匹配(post_title、post_domain、post_url、post_内容、post_标记)与(%s处于布尔模式)”]=trim($search_terms\u clean);
}否则{
$h->vars['select']=$select;
$h->vars['orderby']=“发布日期描述”;
$h->vars['filter_vars']=array();
$where=$this->explodeSearch($h,'post\u title',$search\u terms\u clean)。“或”;
$where.=$this->explodeSearch($h,'post\u url',$search\u terms\u clean)。“或”;
$where.=$this->explodeSearch($h,'post\u content',$search\u terms\u clean);
$where='('.$where.');
$h->vars['filter'][$where]=$h->vars['filter_vars'];
}
$prepared_search=array('select'=>$h->vars['select'],'orderby'=>$h->vars['orderby'],'filter'=>$h->vars['filter']);
返回$U搜索;
}
/**爆炸式搜索短词
* 
*@param字符串$column
*@param string$search\u术语
*@返回字符串(末端去掉“或”)
*/
公共函数搜索($h,$column,$search\u terms)
{
$query='';
foreach(分解(“”,修剪($search_terms))为$word){
如果($word){
$query.=$column.“像%s或”;
$search\u term=urlencode(“.trim($h->db->escape($word))。”;
//转义所有百分比符号以用于LIKE查询:
$search\u te