2012-09-21 74 views
0

所以,我使用PHP的PDO得到以下错误:PDO无效绑定参数号

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined 

现在,据我了解,这个错误当一个参数在查询中使用时,但从来没有妥善绑定。例如,错别字使这成为一个常见的错误。

问题是......我似乎无法找到问题!我已经多次查看了每个参数,并且找不到任何差异。其他事情可能会导致这个问题?我只是滚动一个明显的错字,需要第二组眼睛才能看到?任何帮助将非常感激!请注意,该错误发生在​​上,如果这对您很重要。

$sth = $dbh->prepare(" 
    INSERT INTO administrators 
    (
     org_id, 
     admin_email, 
     passwd, 
     passwd_salt, 
     announcements, 
     logo, 
     design, 
     content, 
     layout, 
     services, 
     contributions_edit, 
     contributions_report, 
     contributions_enable, 
     pledges, 
     calendar, 
     event, 
     survey, 
     email, 
     caller, 
     bulletin, 
     prayer, 
     email_newsletter, 
     member_add, 
     member_edit, 
     passwd_reset, 
     spotlight, 
     profile_status, 
     groups, 
     attendance, 
     sermons, 
     church_info, 
     mail_merge, 
     file_upload, 
     admin_name, 
     administrators, 
     newsletter, 
     outreach, 
     charts, 
     streaming 
    ) 
    VALUES 
    (
     :org_id, 
     :admin_email, 
     :passwd, 
     :passwd_salt, 
     :announcements, 
     :logo, 
     :design, 
     :content, 
     :layout, 
     :services, 
     :contributions_edit, 
     :contributions_report, 
     :contributions_enable, 
     :pledges, 
     :calendar, 
     :event, 
     :survey, 
     :email, 
     :caller, 
     :bulletin, 
     :prayer, 
     :email_newsletter, 
     :member_add, 
     :member_edit, 
     :passwd_reset, 
     :spotlight, 
     :profile_status, 
     :groups, 
     :attendance, 
     :sermons, 
     :church_info, 
     :mail_merge, 
     :file_upload, 
     :admin_name, 
     :administrators, 
     :newsletter, 
     :outreach, 
     :charts, 
     :streaming 
    ) 
    "); 
$sth->bindParam(':org_id,', $org_id); 
$sth->bindParam(':admin_email', $admin_email); 
$sth->bindParam(':passwd', $passwd); 
$sth->bindParam(':passwd_salt', $passwd_salt); 
$sth->bindParam(':announcements', $announcements); 
$sth->bindParam(':logo', $logo); 
$sth->bindParam(':design', $design); 
$sth->bindParam(':content', $content); 
$sth->bindParam(':layout', $layout); 
$sth->bindParam(':services', $services); 
$sth->bindParam(':contributions_edit', $contributions_edit); 
$sth->bindParam(':contributions_report', $contributions_report); 
$sth->bindParam(':contributions_enable', $contributions_enable); 
$sth->bindParam(':pledges', $pledges); 
$sth->bindParam(':calendar', $calendar); 
$sth->bindParam(':event', $event); 
$sth->bindParam(':survey', $survey); 
$sth->bindParam(':email', $email); 
$sth->bindParam(':caller', $caller); 
$sth->bindParam(':bulletin', $bulletin); 
$sth->bindParam(':prayer', $prayer); 
$sth->bindParam(':email_newsletter', $email_newsletter); 
$sth->bindParam(':member_add', $member_add); 
$sth->bindParam(':member_edit', $member_edit); 
$sth->bindParam(':passwd_reset', $passwd_reset); 
$sth->bindParam(':spotlight', $spotlight); 
$sth->bindParam(':profile_status', $profile_status); 
$sth->bindParam(':groups', $groups); 
$sth->bindParam(':attendance', $attendance); 
$sth->bindParam(':sermons', $sermons); 
$sth->bindParam(':church_info', $church_info); 
$sth->bindParam(':mail_merge', $mail_merge); 
$sth->bindParam(':file_upload', $file_upload); 
$sth->bindParam(':admin_name', $admin_name); 
$sth->bindParam(':administrators', $administrators); 
$sth->bindParam(':newsletter', $newsletter); 
$sth->bindParam(':outreach', $outreach); 
$sth->bindParam(':charts', $charts); 
$sth->bindParam(':streaming', $streaming); 
$sth->execute(); 

非常感谢!

+0

你可以做一个var_dump的每个参数传递?如果一个或多个定义不正确,可能会导致您的查询关闭 –

+0

我不相信NULL值会使绑定参数在PDO中失败。 – Nathanael

+0

这只是一个建议。检查下面的答案;似乎一个额外的逗号可能已经把它关掉 –

回答

3
$sth->bindParam(':org_id,', $org_id); 
         ^
         | 
         |_____________ This , is intentional? i guess not. 

$sth->bindParam(':admin_email', $admin_email); 
$sth->bindParam(':passwd', $passwd); 
$sth->bindParam(':passwd_salt', $passwd_salt); 
$sth->bindParam(':announcements', $announcements); 
$sth->bindParam(':logo', $logo); 
$sth->bindParam(':design', $design); 
$sth->bindParam(':content', $content); 
$sth->bindParam(':layout', $layout); 
$sth->bindParam(':services', $services); 
$sth->bindParam(':contributions_edit', $contributions_edit); 
$sth->bindParam(':contributions_report', $contributions_report); 
$sth->bindParam(':contributions_enable', $contributions_enable); 
$sth->bindParam(':pledges', $pledges); 
$sth->bindParam(':calendar', $calendar); 
$sth->bindParam(':event', $event); 
$sth->bindParam(':survey', $survey); 
$sth->bindParam(':email', $email); 
$sth->bindParam(':caller', $caller); 
$sth->bindParam(':bulletin', $bulletin); 
$sth->bindParam(':prayer', $prayer); 
$sth->bindParam(':email_newsletter', $email_newsletter); 
$sth->bindParam(':member_add', $member_add); 
$sth->bindParam(':member_edit', $member_edit); 
$sth->bindParam(':passwd_reset', $passwd_reset); 
$sth->bindParam(':spotlight', $spotlight); 
$sth->bindParam(':profile_status', $profile_status); 
$sth->bindParam(':groups', $groups); 
$sth->bindParam(':attendance', $attendance); 
$sth->bindParam(':sermons', $sermons); 
$sth->bindParam(':church_info', $church_info); 
$sth->bindParam(':mail_merge', $mail_merge); 
$sth->bindParam(':file_upload', $file_upload); 
$sth->bindParam(':admin_name', $admin_name); 
$sth->bindParam(':administrators', $administrators); 
$sth->bindParam(':newsletter', $newsletter); 
$sth->bindParam(':outreach', $outreach); 
$sth->bindParam(':charts', $charts); 
$sth->bindParam(':streaming', $streaming); 
$sth->execute(); 
+0

猜猜我只需要第二组眼睛!谢谢! :)只要StackOverflow允许,我会将其标记为最佳答案! – Nathanael

+0

它发生了。 ;-) – itachi