php CI-发生数据库错误

时间:2016-07-12 16:57:59

标签: php

我在php CI中遇到了这个错误:

  

发生数据库错误

     

错误号码:1064

     

您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以便在''%blackhat%'附近使用正确的语法在第5行的ORDER BY DESC中使用

     

SELECT COUNT mid,mtitle,mtitle_identifier,msinopsis,mauthors,mdirectors,mproducers FROM srt_movie WHERE(mtitle LIKE'%blackhat%'或msinopsis LIKE'%blackhat%'或mauthors LIKE'%blackhat%'或mdirectors LIKE'% blackhat%'或者生产者喜欢'%blackhat%)ORDER BY DESC

     

文件名:C:/xampp/htdocs/sorot/system/database/DB_driver.php

     

行号:691

以下是我在模型中的语法:

$sql1 = "SELECT DISTINCT mid, mtitle, mtitle_identifier, msinopsis, mauthors, mdirectors, mproducers FROM srt_movie WHERE (";
        while (list($key,$val) = each($rwords))

        {
            if($val <> " " AND strlen($val) > 0)
            {
                $sql1 .="mtitle LIKE '%$val%' OR
                        msinopsis LIKE '%$val%' OR
                        mauthors LIKE '%$val%' OR
                        mdirectors LIKE '%$val%' OR
                        mproducers LIKE '%$val%' OR";
            }
        }   
        $sql1 = substr($sql1,0,(strlen($sql1)-4));
        $sql1 .=")";
        $sql1 .="ORDER BY mid DESC";
        if(! is_null($limit))
        {
            $sql1 .="LIMIT $limit OFFSET $offsset";
        }

        //lakukan query
        $query1 = $this->db->query($sql1);
        $result['movie_num'] = $query1->num_rows();
        if($result ['movie_num'] >0)
        {
            $result['movie'] = $this->mark_up_result($words,$query->result());
        }
        else
        {
            return " .";
        }
        return $result;

    }

如何解决?

0 个答案:

没有答案