准备好的声明是否会对文本进行干

时间:2013-03-10 10:20:32

标签: php sql-server pdo

更新:我认为我正面临这个问题http://social.msdn.microsoft.com/Forums/en-US/sqldriverforphp/thread/2a559a42-0ef3-42c8-9e87-08ff7934678a/很快就会回来,如果是这样的话。

我无法理解发生了什么。也许调试工具很糟糕,或者在语句汇编的方式中出现问题,无论如何,我希望有一些提示/可能是另一种处理问题的方法。

我有这样的声明:

$rule_statment = $pdo->prepare(
                "if not exists
                 (select * from menu_availability_rules
                 where
                   (daily_serving_start = :start or
                    daily_serving_start is null and :start is null) and
                   (daily_serving_end = :end or
                    daily_serving_end is null and :end is null) and
                   (weekly_service_off = :weekly or
                    weekly_service_off is null and :weekly is null) and
                   (one_time_service_off = :once or
                    one_time_service_off is null and :once is null))
                 begin
                   insert into menu_availability_rules
                    (daily_serving_start, daily_serving_end,
                     weekly_service_off, one_time_service_off)
                   values (:start, :end, :weekly, :once)
                 end");

在调用execute之前绑定所有必需的参数,但是从SQL Server返回时出现语法错误:

COUNT field incorrect or syntax error

我试过打印出来:

$rule_statment->debugDumpParams();

输出是这样的:

if not exists
                 (select * from menu_availability_rules
                 where
                   (daily_serving_start = :start or
                    daily_serving_start is null and :start is null) and
                   (daily_serving_end = :end or
                    daily_serving_end is null and :end is null) and
                   (weekly_service_off = :weekly or
                    weekly_service_off is null and :weekly is null) and

Params:  4
Key: Name: [6] :start
paramno=0
name=[6] ":start"
is_param=1
param_type=0
Key: Name: [4] :end
paramno=2
name=[4] ":end"
is_param=1
param_type=0
Key: Name: [7] :weekly
paramno=4
name=[7] ":weekly"
is_param=1
param_type=1
Key: Name: [5] :once
paramno=6
name=[5] ":once"
is_param=1
param_type=2

为什么呢?究竟发生了什么?

1 个答案:

答案 0 :(得分:0)

如果在查询中出现多次,PHP似乎不会替换命名参数 - 谁知道:|