【发布时间】:2015-06-23 13:47:19
【问题描述】:
我有一个关于使用 PDO 在 PHP5 中使用的 firebird 2.5 中的参数处理的问题
我有以下查询确实有效,但正如您所见,我需要命名每个参数(完全相同)。
$sql = 'INSERT INTO orderregels
(order_ref, product_ref, variant_ref, magazijn_ref, aantal, code, omschrijving, maat, picklocatie, ean, ehprijs, korting, brutoprijs, regelbedrag, vvp, merk_ref, eenheid_ref, eenheid,
status_ref, btwtarief_ref, btwtarief, gewicht, hscode, atype)
VALUES (
:ORDER_REF,
(select product_ref from productvariant where id=:VARIANT_REF),
:VARIANT_REF2,
:MAGAZIJN_REF,
:AANTAL,
(select code from productvarianten where id=(select variant_ref from productvariant where id=:VARIANT_REF3)),
((SELECT omschrijving FROM producten WHERE id=(SELECT product_ref FROM productvariant WHERE id=:VARIANT_REF4))||\' \'||
(SELECT omschrijving FROM productvariant WHERE id=:VARIANT_REF5)),
(SELECT maat FROM productvariant WHERE id=:VARIANT_REF6),
(select magazijnlocatie from productvariant where id=:VARIANT_REF7),
(select ean from productvariant where id=:VARIANT_REF8),
(select ehprijs from productvariant where id=:VARIANT_REF9),
:KORTING,
((select ehprijs from productvariant where id=:VARIANT_REF10)*(1-(cast(:KORTING2 as numeric(18,3))/100))),
(:AANTAL2 *
((select ehprijs from productvariant where id=:VARIANT_REF11)*(1-(cast(:KORTING3 as numeric(18,3))/100)))),
(select vvp from productvariant where id=:VARIANT_REF12),
(select merk_ref from producten where id=(select product_ref from productvariant where id=:VARIANT_REF13)),
(select eenheid_ref from producten where id=(select product_ref from productvariant where id=:VARIANT_REF14)),
(select omschrijving from eenheden where id=(select eenheid_ref from producten where id=(select product_ref from productvariant where id=:VARIANT_REF15))),
1,
(select btwtarief_ref FROM orders WHERE id=:ORDER_REF2),
(SELECT percentage FROM btwtarieven where id=(select btwtarief_ref FROM orders WHERE id=:ORDER_REF3)),
(select gewicht from productvariant where id=:VARIANT_REF16),
(select hscode from producten where id=(select product_ref from productvariant where id=:VARIANT_REF17)),
1)';
$params = Array(
':ORDER_REF' => $order_ref,
':VARIANT_REF' => $variant_ref,
':VARIANT_REF2' => $variant_ref,
':MAGAZIJN_REF' => 1,
':AANTAL'=> $aantal,
':VARIANT_REF3' => $variant_ref,
':VARIANT_REF4' => $variant_ref,
':VARIANT_REF5' => $variant_ref,
':VARIANT_REF6' => $variant_ref,
':VARIANT_REF7' => $variant_ref,
':VARIANT_REF8' => $variant_ref,
':VARIANT_REF9' => $variant_ref,
':KORTING'=> $korting,
':VARIANT_REF10' => $variant_ref,
':KORTING2'=> $korting,
':AANTAL2' => $aantal,
':VARIANT_REF11' => $variant_ref,
':KORTING3'=> $korting,
':VARIANT_REF12' => $variant_ref,
':VARIANT_REF13' => $variant_ref,
':VARIANT_REF14' => $variant_ref,
':VARIANT_REF15' => $variant_ref,
':ORDER_REF2' => $order_ref,
':ORDER_REF3' => $order_ref,
':VARIANT_REF16' => $variant_ref,
':VARIANT_REF17' => $variant_ref
);
简化版本(不唯一命名每个参数)在数据库工作台等查询编辑器中或在 Delphi 中使用时运行良好。
$sql = 'INSERT INTO orderregels
(order_ref, product_ref, variant_ref, magazijn_ref, aantal, code, omschrijving, maat, picklocatie, ean, ehprijs, korting, brutoprijs, regelbedrag, vvp, merk_ref, eenheid_ref, eenheid,
status_ref, btwtarief_ref, btwtarief, gewicht, hscode, atype)
VALUES (
:ORDER_REF,
(select product_ref from productvariant where id=:VARIANT_REF),
:VARIANT_REF,
:MAGAZIJN_REF,
:AANTAL,
(select code from productvarianten where id=(select variant_ref from productvariant where id=:VARIANT_REF)),
((SELECT omschrijving FROM producten WHERE id=(SELECT product_ref FROM productvariant WHERE id=:VARIANT_REF))||\' \'||
(SELECT omschrijving FROM productvariant WHERE id=:VARIANT_REF)),
(SELECT maat FROM productvariant WHERE id=:VARIANT_REF),
(select magazijnlocatie from productvariant where id=:VARIANT_REF),
(select ean from productvariant where id=:VARIANT_REF),
(select ehprijs from productvariant where id=:VARIANT_REF),
:KORTING,
((select ehprijs from productvariant where id=:VARIANT_REF)*(1-(cast(:KORTING as numeric(18,3))/100))),
(:AANTAL *
((select ehprijs from productvariant where id=:VARIANT_REF)*(1-(cast(:KORTING as numeric(18,3))/100)))),
(select vvp from productvariant where id=:VARIANT_REF),
(select merk_ref from producten where id=(select product_ref from productvariant where id=:VARIANT_REF)),
(select eenheid_ref from producten where id=(select product_ref from productvariant where id=:VARIANT_REF)),
(select omschrijving from eenheden where id=(select eenheid_ref from producten where id=(select product_ref from productvariant where id=:VARIANT_REF))),
1,
(select btwtarief_ref FROM orders WHERE id=:ORDER_REF),
(SELECT percentage FROM btwtarieven where id=(select btwtarief_ref FROM orders WHERE id=:ORDER_REF)),
(select gewicht from productvariant where id=:VARIANT_REF),
(select hscode from producten where id=(select product_ref from productvariant where id=:VARIANT_REF)),
1)';
$params = Array(
':ORDER_REF' => $order_ref,
':VARIANT_REF' => $variant_ref,
':MAGAZIJN_REF' => 1,
':AANTAL'=> $aantal,
':KORTING'=> $korting
);
它给了我以下错误:
致命错误:带有消息的未捕获异常“PDOException” 'SQLSTATE[HY000]: 一般错误:-804 动态 SQL 错误 SQL 错误代码 = -804 SQLDA 结构中的值不正确 '
真的每次我使用一个参数(即使它具有相同的名称)我都必须唯一地命名它们并按照它们在语句中使用的确切顺序放置它们吗?它带走了命名参数的所有优点......
感谢您提供任何信息,
克里斯蒂安
【问题讨论】:
-
Firebird 没有命名参数,因此客户端组件有时会模拟它。显然 PDO 不处理具有相同名称的多个参数。
标签: php pdo parameters firebird