PHP准备语句中的多个值
使用准备好的语句,我得到了23个要输入的值(见下文)。这是否意味着我需要输入23?放置或是否存在某种默认/速记PHP准备语句中的多个值,php,mysqli,prepared-statement,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_sta
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似乎有点过多。这应该适合您,要将所有输入速记绑定到查询中,我建议您使用以下代码:
$placeholders = implode(', ', array_fill(0, 23, '?'));
$stmt = $connection->prepare("INSERT INTO table
(
... rest of the statement....
)
VALUES ($placeholders)");
这应该适合您,将所有输入简写绑定到查询中,我建议您使用以下代码:
$placeholders = implode(', ', array_fill(0, 23, '?'));
$stmt = $connection->prepare("INSERT INTO table
(
... rest of the statement....
)
VALUES ($placeholders)");
当然,如果您有23个参数,那么您需要绑定23个参数。如果您有23个参数,那么您必须绑定23个参数。如果命名参数令人困惑,您可以使用命名参数。检查文档:@JigarShah Except OP正在使用标记中所述的
mysqli_uu
。例如,mysqli_stmt::bind_param手册中的用户注释有关于如何绑定动态数量的值的提示。当然,如果您拥有23个参数,则需要绑定23个参数。如果您拥有23个参数,则必须绑定23个参数参数。如果命名参数令人困惑,则可以使用它。检查文档:@JigarShah Except OP正在使用标记中所述的mysqli\uu
。例如,mysqli\u stmt::bind\u param手册中的用户注释有关于如何绑定动态数量的值的提示。@Dan没问题,请记住不要将包含用户输入的变量放入prepare
语句中,只有硬编码的变量,如使$placeholder
成为长SQL语句的缩写,才是例外情况之一。@Dan没问题,请记住不要将包含用户输入的变量放入prepare
语句中,只有硬编码的变量,如将$placeholder
转换为长SQL语句,才是例外情况之一。