SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配 - 正确计数

时间:2015-06-17 11:53:36

标签: php mysql pdo

过去几天我多次查看此查询,但我看不出问题所在:

$sql = "INSERT INTO tbl_name (
                id, gender, name, lastname, 
                address1, address2, address3, address4, address5, address6, address7, address8, postcode, country, 
                email, optin, misc1, misc2, misc3, 
                client_id, batch, filename, origin, raw_id, date_imported, date_time_imported, 
                date_exported, returned_status, date_returned, 
                adf_organisation, adf_property, adf_street, adf_locality, adf_town, adf_postal_county, adf_postcode, adf_dps, adf_country, adf_result_code, 
                fulfilment_batch_id, added_by
            ) VALUES (
                :id, :gender, :firstname, :lastname, 
                :address1, :address2, :address3, :address4, :address5, :address6, :address7, :address8, :postcode, :country, 
                :email, :optin, :misc1, :misc2, :misc3, 
                :client_id, :batch, :filename, :origin, :raw_id, :date, :datetime_imported, 
                :date_exported, :returned_status, :date_returned, 
                :adf_org, :adf_property, :adf_add1, adf_add2, :adf_add4, :adf_add5, :adf_postcode, :dps, :adf_country, :result_code, 
                :fulfilment_batch_id, :member_name
            )";

$parameters_array = array(
                'id' => '0', 'gender' => $gender, 'firstname' => ucwords(strtolower($firstname)), 'lastname' => ucwords(strtolower($lastname)), 
                'address1' => $address1, 'address2' => $address4, 'address3' => $address3, 'address4' => $address42, 'address5' => $address5, 'address6' => $address6, 'address7' => $address7, 'address8' => $address8, 'postcode' => $postcode, 'country' => $country,    
                'email' => $email_address, 'optin' => $opt_in, 'misc1' => $misc1, 'misc2' => $misc2, 'misc3' => $misc3, 
                'client_id' => $client_id, 'batch' => $batch, 'filename' => $filename, 'origin' => $origin, 'raw_id' => $raw_id, 'date' => $date, 'datetime_imported' => $datetime_now, 'date_exported' => '0', 'returned_status' => '0',   'date_returned' => '0',
                'adf_org' => $organisation, 'adf_property' => $property, 'adf_add1' => $address1, 'adf_add2' => $address2,  'adf_add4' => $address4, 'adf_add5' => $address5, 'adf_postcode' => $postcode, 'dps' => $delivery_point_suffix, 'adf_country' => ucwords($country), 'result_code' => $result_code, 
                'fulfilment_batch_id' => '', 'member_name' => $member_name
  

$ insert = $ fulfillilment_db_connection-> conn-> prepare($ sql);

$insert->execute($parameters_array);

这是转储输出:

SQL: [1079] INSERT INTO tbl_name ( id, gender, name, lastname, address1, address2, address3, address4, address5, address6, address7, address8, postcode, country, email, optin, misc1, misc2, misc3, client_id, batch, filename, origin, raw_id, date_imported, date_time_imported, date_exported, returned_status, date_returned, adf_organisation, adf_property, adf_street, adf_locality, adf_town, adf_postal_county, adf_postcode, adf_dps, ad Params: 41 Key: Name: [3] :id paramno=-1 name=[3] ":id" is_param=1 param_type=2 Key: Name: [7] :gender paramno=-1 name=[7] ":gender" is_param=1 param_type=2 Key: Name: [10] :firstname paramno=-1 name=[10] ":firstname" is_param=1 param_type=2 Key: Name: [9] :lastname paramno=-1 name=[9] ":lastname" is_param=1 param_type=2 Key: Name: [9] :address1 paramno=-1 name=[9] ":address1" is_param=1 param_type=2 Key: Name: [9] :address2 paramno=-1 name=[9] ":address2" is_param=1 param_type=2 Key: Name: [9] :address3 paramno=-1 name=[9] ":address3" is_param=1 param_type=2 Key: Name: [9] :address4 paramno=-1 name=[9] ":address4" is_param=1 param_type=2 Key: Name: [9] :address5 paramno=-1 name=[9] ":address5" is_param=1 param_type=2 Key: Name: [9] :address6 paramno=-1 name=[9] ":address6" is_param=1 param_type=2 Key: Name: [9] :address7 paramno=-1 name=[9] ":address7" is_param=1 param_type=2 Key: Name: [9] :address8 paramno=-1 name=[9] ":address8" is_param=1 param_type=2 Key: Name: [9] :postcode paramno=-1 name=[9] ":postcode" is_param=1 param_type=2 Key: Name: [8] :country paramno=-1 name=[8] ":country" is_param=1 param_type=2 Key: Name: [6] :email paramno=-1 name=[6] ":email" is_param=1 param_type=2 Key: Name: [6] :optin paramno=-1 name=[6] ":optin" is_param=1 param_type=2 Key: Name: [6] :misc1 paramno=-1 name=[6] ":misc1" is_param=1 param_type=2 Key: Name: [6] :misc2 paramno=-1 name=[6] ":misc2" is_param=1 param_type=2 Key: Name: [6] :misc3 paramno=-1 name=[6] ":misc3" is_param=1 param_type=2 Key: Name: [10] :client_id paramno=-1 name=[10] ":client_id" is_param=1 param_type=2 Key: Name: [6] :batch paramno=-1 name=[6] ":batch" is_param=1 param_type=2 Key: Name: [9] :filename paramno=-1 name=[9] ":filename" is_param=1 param_type=2 Key: Name: [7] :origin paramno=-1 name=[7] ":origin" is_param=1 param_type=2 Key: Name: [7] :raw_id paramno=-1 name=[7] ":raw_id" is_param=1 param_type=2 Key: Name: [5] :date paramno=-1 name=[5] ":date" is_param=1 param_type=2 Key: Name: [18] :datetime_imported paramno=-1 name=[18] ":datetime_imported" is_param=1 param_type=2 Key: Name: [14] :date_exported paramno=-1 name=[14] ":date_exported" is_param=1 param_type=2 Key: Name: [16] :returned_status paramno=-1 name=[16] ":returned_status" is_param=1 param_type=2 Key: Name: [14] :date_returned paramno=-1 name=[14] ":date_returned" is_param=1 param_type=2 Key: Name: [8] :adf_org paramno=-1 name=[8] ":adf_org" is_param=1 param_type=2 Key: Name: [13] :adf_property paramno=-1 name=[13] ":adf_property" is_param=1 param_type=2 Key: Name: [9] :adf_add1 paramno=-1 name=[9] ":adf_add1" is_param=1 param_type=2 Key: Name: [9] :adf_add2 paramno=-1 name=[9] ":adf_add2" is_param=1 param_type=2 Key: Name: [9] :adf_add4 paramno=-1 name=[9] ":adf_add4" is_param=1 param_type=2 Key: Name: [9] :adf_add5 paramno=-1 name=[9] ":adf_add5" is_param=1 param_type=2 Key: Name: [13] :adf_postcode paramno=-1 name=[13] ":adf_postcode" is_param=1 param_type=2 Key: Name: [4] :dps paramno=-1 name=[4] ":dps" is_param=1 param_type=2 Key: Name: [12] :adf_country paramno=-1 name=[12] ":adf_country" is_param=1 param_type=2 Key: Name: [12] :result_code paramno=-1 name=[12] ":result_code" is_param=1 param_type=2 Key: Name: [20] :fulfilment_batch_id paramno=-1 name=[20] ":fulfilment_batch_id" is_param=1 param_type=2 Key: Name: [12] :member_name paramno=-1 name=[12] ":member_name" is_param=1 param_type=2 

表中有41个字段,41个参数和41个值持有者。

我唯一能想到的是,它不喜欢其中一些空字符串。

任何帮助将不胜感激。我已经浏览了相同标题的其他帖子,想出了如何使转储代码工作,以便我可以输出它试图插入的信息。我只是看不到错误。

1 个答案:

答案 0 :(得分:0)

解决

我无法在数组中使用php函数 - 很无聊,我错过了:off adf_add2。

所以,对于其他任何人来说,PDO数组中的PHP函数不是你的朋友,在计算参数时,请检查所有:是否存在。

感谢您的帮助,一次为他们提供一个参数: - )