存储图像路径/名称的数组:
$wall_filenames[]
$wall_filenames:
Array ( [0] => wallpapers/2014/03/calendar-thumbnail-520x264.jpg
[1] => wallpapers/2014/03/calendar-preview2-786x305.jpg )
MySQL查询:
$sql = "INSERT INTO walls(wall_name, wall_thumbnail_path, wall_preview1_path,
wall_preview2_path, wall_preview3_path,
upload_date, d_1280x800_path, d_1366x768_path, d_1920x1080_path,
p_640x960_path, p_640x1136_path, p_720x1280_path, p_768x1280_path,
p_1080x1920_path, t_1024x768_path, t_2048x1536_path)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$insert_wall = $connectDB->prepare($sql);
所以问题是,该表包含几列。但是当我插入一次时,没有必要上传所有文件,在我上面的示例中,我只上传了两个。我需要做的是将这些数组元素添加到我的表中的适当列。在这种情况下,我希望将$wall_filenames[0]
存储到wall_thumbnail_path
,将$wall_filenames[1]
存储到wall_preview2_path
。我不确定如何使用bind_param()
绑定数组以指向表中的正确列。
答案 0 :(得分:0)
在致电bind_param
时包含数组索引:
$insert_wall->bind_param('sss...', $wall_name, $wall_filenames[0], $wall_filenames[1], ...);
答案 1 :(得分:-2)
要有创意。
在数据库中存储常数时,绝对没有意义。只需开发一些命名策略,然后删除所有这些路径列,并根据命名策略检查磁盘中的文件。