I do a sql query that checks if a row is present … if there is the tuple I do INSERT INTO Setting else UPDATE. UserID is the primary key. I wanted to try to do it directly in a single query in php … is it possible? I can somehow use the command not exist?
enter code here
$query = 'INSERT INTO Settings SET
userID = '.$uid.',
visibility = -1,
notify_icon = true,
notify_connect_friend = true,
notify_near_friend = true,
ringer = true,
vibration = true
';
$query = 'UPDATE Settings SET
visibility = '.$visibility.',
notify_icon = '.$notify_icon.',
notify_connect_friend = '.$notify_connect_friend.',
notify_near_friend = '.$notify_near_friend.',
ringer = '.$ringer.',
vibration = '.$vibration.'
WHERE
userID = '.$uid.'
';
Yes, there is a way with a single query. Take a look at On duplicate key update