2015-06-23 72 views
1

我有一个关于使用PDOPDO火鸟和参数

在火鸟2.5参数处理在PHP5中使用的问题,我有以下查询的工作,但你可以看到,我需要命名每个参数(完全一样)。

$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使用数据库工作台或当查询编辑器细。

​​

它给了我下面的错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: -804 Dynamic SQL Error SQL error code = -804 Incorrect values within SQLDA structure '

这是真的,每次我用一个参数(即使它具有相同的名称),我唯一他们的名字和地点他们按照他们在声明中使用的确切顺序?它需要命名参数远的所有优点...

感谢任何信息,

克里斯蒂安

+1

Firebird没有命名参数,因此客户端组件有时会模拟它。显然,PDO不能处理具有相同名称的多个参数。 –

回答

0

是的,这是真的。有关详细信息,请参阅this answer

It takes all the advantages of named parameters away...

一点都没有,因为它们的主要优点是防止SQL注入。

链接的答案也提出了一个建议,如何添加的那种你想要绑定的“自制”的支持。

顺便说一句,我很惊讶你可以连接到firebird。