Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding to a database

Status
Not open for further replies.

martinb7

Programmer
Jan 5, 2003
235
GB
Is there any way of making a database column (e.g id) + 1 if someone clicks jim.php for example?

<a href=&quot;jim.php&quot;[/blue]>jim</a>

Is there any way of embedding it to the link or in jim.php?
 
KempCGDR:

Your solution is not concurrency-safe. The increment of a value in a database should be performed as an atomic operation.

Suppose the value to be incremented is X. By reading, incrementing and writing as separate operations, the following is very possible:[ol][li]One user reads the value, and gets X.[/li][li]A second user reads the value and gets X.[/li][li]The first user increments the value to X + 1 then writes the new value to the database.[/li][li]The second user then increments the value to X + 1 and does the name.[/li][/ol]
Now the value in the database is X + 1, when it should be X + 2.

Most SQL-based database servers will allow an increment to be performed as such:

UPDATE tablename SET columnname = columnname + 1 WHERE anothercolumn = somecondition. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top