I have an IF NOT EXISTS statement. IF it doesn't exist an INSERT statement follows. IF EXISTS I need to understand what is/can be returned so that I can interpret it with PHP.
so:
IF NOT EXISTS (SELECT id FROM users WHERE lname='SMITH') INSERT INTO users (lname='SMITH') I thought that the negative would return no result so could use a standard
if ($result){echo "record added";} else {echo "duplicate - no record added";} But that's not what's happening and I'm not sure how to achieve what I need - any suggestions?
Thank you for your kind attention.
$resultbeing defined? SQL is still going to generate an 'I did something' object, although I'm not entirely sure what that looks like in PHP. To my knowledge, if no row is inserted, you'll get a (fairly) standard code100; however, I'm not sure what the way you've written the SQL is going to do to that. I'd prefer re-writing it into a form which will always execute theINSERT, but it won't always have a row to do so.