0

更新:我想我正面临这个问题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

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

4

1 回答 1

0

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

于 2013-03-10T10:37:52.183 回答