htmlentities在推进符号1.2中无法正常工作



问题

  • 将单引号替换为双引号

    echo$movement_data

输出字符串:

    '200407', '200396', '200397', '200398', '200399', '200400', '200401', '200402', '200403', '200404'

推进代码:

         $c->add(VmemberDetailsPeer::PERSON_ID,array(htmlentities($movement_data, ENT_QUOTES)),Criteria::IN);
         echo $c->toString();
         $person = VmemberDetailsPeer::doSelect($c);

推进查询

 Criteria: SQL (may not be complete): SELECT FROM vmember_details WHERE vmember_details.PERSON_ID IN (:p1) Params: vmember_details.PERSON_ID => ''200407', '200396', '200397', '200398', '200399', '200400', '200401', '200402', '200403', '200404''

输出:

   array(0) { }

我需要什么

  • 我需要在where子句中传递相同的逗号分隔字符串。

  • 如果我直接推送数组($movement_data)中的movement_datacomm分隔字符串

  • 它用特殊字符输出,比如'\2222\',等等…我在where子句中有html特殊字符

不使用Htmlentities结果推进查询

         SELECT FROM vmember_details 
   WHERE vmember_details.PERSON_ID IN (:p1) 
   Params: vmember_details.PERSON_ID => ''200407', '200396', '200397', '200398', '200399', '200400', '200401', '200402', '200403', '200404''

我尝试过的爆炸生成字符串到数组的解决方案:

 $x=explode(",",$movement_data);

输出:

      Array
     (
      [0] => '200407'
      [1] => '200396'
      [2] => '200397'
      [3] => '200398'
     )

       $c->add(VmemberDetailsPeer::PERSON_ID,$x,Criteria::IN);
         echo $c->toString();
         $person = VmemberDetailsPeer::doSelect($c);

推进查询输出:

      SELECT FROM vmember_details WHERE vmember_details.PERSON_ID IN (:p1,:p2,:p3,:p4,:p5,:p6,:p7,:p8,:p9,:p10) Params: vmember_details.PERSON_ID => ''200407'', vmember_details.PERSON_ID => ' '200396'', vmember_details.PERSON_ID => ' '200397'', vmember_details.PERSON_ID => ' '200398'', vmember_details.PERSON_ID => ' '200399'', vmember_details.PERSON_ID => ' '200400'', vmember_details.PERSON_ID => ' '200401'', vmember_details.PERSON_ID => ' '200402'', vmember_details.PERSON_ID => ' '200403'', vmember_details.PERSON_ID => ' '200404''
  • 我需要传递相同的字符串where子句

从字符串中提取数据,输出为数组

$x=explode(",",$movement_data);
Array
(
    [0] => '200407'
    [1] => '200396'
    [2] => '200397'
    [3] => '200398'
)

然后将该数组传递给创建SQL语句的函数。

好的,现在请看下面的代码示例

$a1 = array(1,2,3);
$a2 = array('1','2','3');
$a3 = array("'1'","'2'","'3'");
print_r($a1);
print_r($a2);
print_r($a3);

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
Array
(
    [0] => '1'
    [1] => '2'
    [2] => '3'
)

第一个数组$a1包含整数,第二个数组包含带数字的字符串,第三个数组包含用单引号括起来的数字的字符串。

这正是你的问题!

您必须删除数字中的单引号,因为驱动程序将专门处理它们(用\代替),这就是您观察到的:

SELECT FROM vmember_details 
WHERE vmember_details.PERSON_ID IN (:p1) 
Params: vmember_details.PERSON_ID => ''200407', '200396', '200397', '200398', '200399', '200400', '200401', '200402', '200403', '200404''

事实上,那里发生了一些不同的事情。您向语句传递了一个包含单引号的字符串。驱动程序检查字符串,遇到单引号,并将其替换为斜杠单引号。

相关内容

  • 没有找到相关文章

最新更新