i want to know what happens if there is a Insertion query in two function running in parallel or if query is inside a foreach loop…
> one more thing is my table has a AUTO INC field, so if two insertion query runs on same table at the same time , then what happens ? will it give error?
how to avoid any errors and do dis successfully?
actually im trying to do my task in parallel in order to increase speed…
d sql part, i have put some code inside a function, [in between these quries come]…
and im calling the function via foreach loop to do the work in parallel…
and r u sure about it?
bcause this table contains some pattern,
>when finds a pattern, it first searches the table if that pattern already exist, only when its not present it runs the insertion query and inserts that pattern…
ya i thought somwat similar but will it not cause any error when it encounters a duplicate key ???
and secondly i am doin insert because if the pattern exists in the table then, it will that particular records pattern no and store it in a var, this info will be used in the later part of the code …
>and wat were u telling abt the foreach loop, is it ok considering the situation ?
your application code would catch the error from the database, and generate a user-friendly error message exactly like the error message you currently produce when you do the SELECT and find the entry that you want to insert already exists
The place to start is with the SQL for the insert.
After the call the first thing you need to test for is if the SQL failed with a duplicate key.
Rearrange the way that the code works to do away with the inefficient foreach. If you do need a loop then move the SQL calls outside the loop so that the loop is only running on PHP variables that have already been loaded from the database call.
the foreach is not being used now… there is only one foreach now, which takes the contents frm array,…
however the sql is inside a few for loops, where i dnt think most of the loops can be avoided…
anyway thanks a lot guys…