//创建表模型
$news_table=new news();
//创建相应的适配器
$db=$news_table->getAdapter();
//准备好sql语句
$sql=$db->quoteInto("select title,pubDate from news where title like '%$keyword_arr[0]%'");
//获取结果集
$res=$db->query($sql)->fetchAll();
我需要模糊查询,有意要带%号,而且里面还有变量名$号,数组的下标运算符[]号,但又要防止别人用%之类的这些东西来Sql注入,这句话该怎么写啊??

解决方案 »

  1.   

    加一个 mysql_real_escape_string();
    不过mysql_real_escape_string不转义 % 和 _ 所以可以先 str_replace(),去掉不想要的符号。
      

  2.   

    这句Sql可以帮忙写出来给我试下不
    我是菜鸟啊
      

  3.   

    这句sql能查询出结果,但是在我的错误日志文件里记录了1个错误和1个警告
    PHP Warning:  Missing argument 2 for Zend_Db_Adapter_Abstract::quoteInto(),
    called in E:\myenv\Apache\htdocs\news\application\controllers\NewsqueryController.php on line 44 and defined in E:\myenv\Apache\htdocs\news\library\Zend\Db\Adapter\Abstract.php on line 927PHP Notice:  Undefined variable: value in 
    E:\myenv\Apache\htdocs\news\library\Zend\Db\Adapter\Abstract.php 
    on line 930
    不晓得哪里有问题
      

  4.   

    1、Abstract.php 927 行的 end_Db_Adapter_Abstract::quoteInto() 函数丢失了参数2,即你少传了一个参数
    2、PHP Notice:  Undefined variable: value 
    $value 没有定义,在 Abstract.php 930 行
     
      

  5.   

    mysql_real_escape_string

    mysql_escape_string有什么分别??
      

  6.   

    $db->quoteInto("select title,pubDate from news where title like '%$keyword_arr[0]%'");
    方法 quoteInto 需要有两个参数to #7
    后者已列入过时系列