Mysql $ stmt-> execute(array($ variable));没有按预期工作

时间:2014-01-08 08:36:47

标签: mysql

名为2_1_paidused

的Mysql
NumberRenamed | Active
-----------------------
 40           |  1
 41           |  1

如果Active包含0

,请尝试创建将?设置为NumberRenamed的代码

这是代码

$stmt_test = $db->prepare('UPDATE 2_1_paidused SET Active=0 WHERE NumberRenamed IN (?)');
$stmt_test->execute( array($value_execute_sql_paidused_for_inactive_rows) );

$value_execute_sql_paidused_for_inactive_rows = '40,41';

print_r(array($value_execute_sql_paidused_for_inactive_rows));

Array ( [0] => 40,41 ) 

结果0Active仅针对NumberRenamed 40而不是针对41而设置。

如果将代码更改为$stmt_test = $db->prepare('UPDATE 2_1_paidused SET Active=0 WHERE NumberRenamed IN ('. $value_execute_sql_paidused_for_inactive_rows. ');'); 然后所有工作(两个行的值都设置为0)

我需要纠正什么?

1 个答案:

答案 0 :(得分:1)

我认为你真的不想运行这个查询:

UPDATE 2_1_paidused SET Active=0 WHERE NumberRenamed IN ('40,41')

您可能想要使用两个参数:

UPDATE 2_1_paidused SET Active=0 WHERE NumberRenamed IN (?, ?)

...然后使用两项数组调用execute()