Is it better to use INSERT, REPLACE or ON DUPLICATE KEY UPDATE, to update a row in my database?
I’m currently using:
mysql_query("insert into pages (pages_id, pagename, pagedesc, pagekey, pagecont) values('$pages_id', $pagename', '$pagedesc', '$pagekey', '$pagecont')");
to create new rows in the DB.
pages_id is an auto_increment field in the mysql database. I’m not sure which is the best way to update an existing row in the database?
If you are updating an existing row (and you’re 100% sure it exists), definitely go for UPDATE.
BUT
If you are “updating” a row which may not exist, go for “INSERT…ON DUPLICATE KEY UPDATE”.