php - how to relate images to article id -
i creating website using php , mysql in want save part of images' name article id.
eg: image_[$articleid]_1.jpg
currently taking article id "querying last id article table , adding 1 it".
i want know whether right way it, because giving article id images before inserting actual article database.
in worst case scenario wondering happen if 10 users inserting article @ same time.
does of know proper logic accomplish or doing right thing?
yes, run trouble in situation. there 2 solutions this:
use auto-increment column; insert new article database before creating image filename, , update new record afterwards.
create lock on images table before start insert records, , release once you're done updating database.
option 1 preferred option; allows concurrent use (nobody has wait before other users finished), , relieves of task of determining last id.
Comments
Post a Comment