mysqli 준비 문을 사용하여 데이터베이스에 데이터를 삽입하려고 하면 오류가 발생할 수 있습니다. "유형 정의 문자열의 요소 수가 바인드 변수 수와 일치하지 않습니다." 이 오류는 SQL 쿼리의 자리 표시자(?) 수와bind_param에 전달된 유형 정의 문자열의 문자 수가 일치하지 않을 때 발생합니다.
제공된 예에는 65개의 자리 표시자가 있습니다. 쿼리의 마커와 65개의 변수가 바인딩_param에 전달됩니다. 단, 코드 스니펫에는 유형 정의 문자열이 지정되어 있지 않으므로 문자 수가 바인드 변수 수와 일치하는지 확인할 수 없습니다.
유형 정의 문자열에는 자리 표시자와 동일한 수의 문자가 포함되어야 합니다. SQL 쿼리에서 각 문자는 해당 자리 표시자의 데이터 유형을 나타냅니다. 예를 들어, 세 개의 자리 표시자가 있는 SQL 쿼리에서 bind_param에는 세 개의 자리 표시자가 모두 문자열임을 나타내기 위해 "sss"와 같은 세 문자가 포함된 유형 정의 문자열이 필요합니다.
오류를 해결하려면 다음을 확인하세요.
다음은 유형 정의 문자열이 포함된 수정된 예입니다.
// Preparing our query statement via mysqli which will auto-escape all bad characters to prevent injection $query3 = 'INSERT INTO datashep_AMS.COMPLETE_APPLICATIONS ( project_name, status, funding_requested, project_title, program, county, parish, name_of_watercourse, which_is_a_tributary_of, name_of_applicant, contact_person_or_project_supervisor, relationship_to_organization, business_phone, home_phone, email, signature_of_thesis_or_study_supervisor, mailing_address, postal_code, website, mailing_address_for_payment, hst_registration_no, total_cost_dollar, total_cost_percent, dollar_amount_requested_from_nbwtf, percent_amount_requested_from_nbwtf, descriptive_summary, background_of_organization, mandate, years_in_existence, membership, accomplishments, previous_project_name, previous_project_number, previous_project_amount_received_from_nbwtf, summary_of_activities, summary_of_Results, project_title_2, reason_and_or_purpose, objectives, project_description, methods, equipment_and_materials_required, personnel_required, proposed_start_date, proposed_end_date, type_of_data_to_be_stored, where_will_it_be_housed, monitoring, short_term_achievement, long_term_achievement, previous_studies, required_permits, consultants, short_term_commitment, long_term_commitment, project_duration, project_evaluation, promotion_of_project, promotion_of_client, publication_of_results, community_benefits, effects_on_traditional_uses, possible_changes_in_public_access_to_areas, possible_impact_on_wildlife_and_or_environment, likelihood_of_future_requests_for_funding, list_all_other_funding_sources_for_this_project ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )'; // "Preparing" the query using mysqli->prepare(query) -- which is the equivalent of mysql_real_escape_string -- in other words, it's the SAFE database injection method $stmt = $dbConnection->prepare($query3); // "Bind_param" == replace all the "?"'s in the aforementioned query with the variables below $stmt->bind_param( "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", $project_name, $status, $funding_requested, $project_title, $program, $county, $parish, $name_of_watercourse, $which_is_a_tributary_of, $name_of_applicant, $contact_person_or_project_supervisor, $relationship_to_organization, $business_phone, $home_phone, $email, $signature_of_thesis_or_study_supervisor, $mailing_address, $postal_code, $website, $mailing_address_for_payment, $hst_registration_no, $total_cost_dollar, $total_cost_percent, $dollar_amount_requested_from_nbwtf, $percent_amount_requested_from_nbwtf, $descriptive_summary, $background_of_organization, $mandate, $years_in_existence, $membership, $accomplishments, $previous_project_name, $previous_project_number, $previous_project_amount_received_from_nbwtf, $summary_of_activities, $summary_of_Results, $project_title_2, $reason_and_or_purpose, $objectives, $project_description, $methods, $equipment_and_materials_required, $personnel_required, $proposed_start_date, $proposed_end_date, $type_of_data_to_be_stored, $where_will_it_be_housed, $monitoring, $short_term_commitment, $long_term_achievement, $previous_studies, $required_permits, $consultants, $short_term_commitment, $long_term_commitment, $project_duration, $project_evaluation, $promotion_of_project, $promotion_of_client, $publication_of_results, $community_benefits, $effects_on_traditional_uses, $possible_changes_in_public_access_to_areas, $possible_impact_on_wildlife_and_or_environment, $likelihood_of_future_requests_for_funding, $list_all_other_funding_sources_for_this_project ); // Perform the actual query! $stmt->execute();
위 내용은 준비된 명령문에서 'mysqli_stmt::bind_param(): 문자 수 및 바인드 변수 불일치' 오류가 발생하는 이유는 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!