I am going to be logging the IP addresses that my users log in with. To do this, I have a simple table with 3 columns: user, ip, time. time is the time at which they last logged in with that address.
When they log in, I want to insert a row into the database containing the IP they logged in with, and the time they logged in.
If a row with the same user AND same ip already exists, I just want to update the time. A more general question:
How can I INSERT a row, or UPDATE it if two (or more) of its columns are the same?
You just need to create composite unique key
user + ipand useINSERT ON DUPLICATE KEY UPDATETo create index use something like