我的代码中出现MYSQL错误

Bog*_*tin 0 php mysql

我的代码中有这个erorr:

致命错误:不能重新声明search_results()(以前在一个声明:\ WAMP\WWW \包括\ func.inc.php:4)A:\ WAMP\WWW \包括第39行上调用堆栈\ func.inc.php

在那个文件中我有:

<?php

function search_results($keywords){
    $returned_results = array();
    $where = "";

    $keywords = preg_split('/[\s]+/',$keywords);
    $total_keywords = count($keywords);

        foreach($keywords as $key=>$keyword){
            $where .= "`article_content` LIKE '%$keyword%'";
                if($key != ($total_keywords - 1)){
                    $where .= " AND ";
                }
        }

    $results = "SELECT *  FROM `articles` WHERE $where";
    $results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0 ;
    if($results_num === 0){
        return false;
    }
    else{

        while($results_row = mysql_fetch_assoc($results)){
            $returned_results[] = array(

                    'article_title' =>$results_row['article_title'],
                    'article_content' =>$results_row['article_content'],
                    'article_timestamp' =>$results_row['article_timestamp'],
                    'article_id' =>$results_row['article_id']

            );
        }

        return $returned_results;

    }
}
?>
Run Code Online (Sandbox Code Playgroud)

我不知道是什么问题.请帮助我尽可能快地解决这个错误!提前致谢

Col*_*dus 6

问题不在于MYSQL,而是包含该文件两次.

  • 你可以通过使用`include_once`或者更确切地说`require_once`来解决这个问题. (2认同)