PHP准备语句中的多个值

时间:2017-07-19 10:57:53

标签: php mysqli prepared-statement

使用准备好的陈述,我已经输入了23个值(见下文)。这是否意味着我需要打出23?展示位置还是有某种默认/速记?

INSERT INTO table 
            (
            job_id, property_title, property_location, property_price, number_of_bedrooms, 
            number_of_receptions, number_of_bathrooms, epc, train_station_miles, 
            garden_acres, garage, off_road_parking, main_photo, 
            photo_1, photo_2, return_email, office, 
            additional_information, timestamp_added, added_by_user_id, timestamp_updated, 
            updated_by_user_id, status_id
            ) 
            VALUES (?, ?, ?, ?,......etc x 23)

我之前从未想过这个,因为我只使用了较少数量的值,但如果有某种速记,23似乎有点过分

1 个答案:

答案 0 :(得分:2)

这应该适合您,将您的所有输入速记绑定到查询中我建议使用此代码:

$placeholders = implode(', ', array_fill(0, 23, '?'));

$stmt = $connection->prepare("INSERT INTO table 
            (
           ... rest of the statement....
            ) 
            VALUES ($placeholders)");