In MYSQL how do I update (not replace) a row if it exists else create a new row.
The column that I need to test is not the primary key, it holds an email address.
basically I have a table that stores emails and other random data. I reference the rows as saved sessions by the primary-unique-auto-incriminating-number column (id)
The reason I uses the id column to refer to the session data rather than the email column is because the email is entered by the user who has no idea about the id columns existence.
EDIT: And the reason why I am not refering to the session by the email is because emails are too/different lengths (long story but they make my QR Codes all different sizes and I don't wan't to expose emails)
I am pretty sure of two things:
REPLACE INTO
this looks like it will destroy my id number as this method copies the row while it removes the old
and
ON DUPLICATE KEY UPDATE
this seems require comparison of a unique key (id) which is not what I need it would be better if I could do something like:
ON DUPLICATE email UPDATE
or something like this (but I don't think it is valid MYSQL):
var email='email@address.com';
var mysql=
"UPDATE table SET (...) WHERE email='"+email+"' "+
"IF @@ROWCOUNT=0 "+
"INSERT INTO table VALUES (...)";
MYSQL can't be THAT ridged can it?