I am doing an update to a table for a row that may not exist. If it doesn’t exist, I need to do an insert. I was initially planning on knowing that I needed to do an insert based on a negative return value from the update statement, but it isn’t returning anything negative.
How can I know that the update didn’t do anything? Do another query seeing if anything is there? Or maybe a query before?
Thanks!
Use http://php.net/manual/en/function.mysql-affected-rows.php
If you’re using
mysqliinstead ofmysql(mysqlwas deprecated a long time ago), it’smysqli_affected_rows.