IF NOT EXISTS INSERT, ELSE UPDATE -- Is it possible?

Hey, Im wondering if you can do this in SQL. I have searched google and can’t find what I’m looking for to explain it to me.

Is this possible? What am I doing wrong?
Or is this something I should do through PHP with multiple queries?

Basically it’s a conditional statement.
These are fake values, Im just trying to learn if it can be done


    IF 
    NOT EXISTS 
        (
        SELECT user_id, bot_id 
        FROM tmp_battles 
            
        WHERE user_id = 1 
        AND bot_id = 5
        ) 
        
    THEN 
        
        INSERT INTO tmp_battles 
        SET  
        user_id = 1,
        bot_id = 2
            
    
    
    ELSE

        UPDATE tmp_battles
        SET
        user_id = 1,
        bot_id = 55,
        
        WHERE user_id = 10
        AND bot_id = 55
        
    END IF

Or what about something like this:

 IF 
   (SELECT COUNT(*) FROM items WHERE id = 1) > 10
THEN
    DO SOMETHING
ELSE
   DO SOMETHING ELSE

yes, it can be done

check in the mysql manual for the INSERT statement with ON DUPLICATE KEY UPDATE clause

Thank you for reply Rudy. I am looking at the ON DUPLICATE KEY right now.
My question I suppose is,

With an AUTO_INCREMENT column named id as my PRIMARY KEY
This probably will never have a duplicate.

Is there a way to check if there is a duplicated of assign_bot and assign_user?

            INSERT INTO tmp_battles
            SET 
            `assign_bot` = '$bot[id]',
            `assign_user` = '{$sess->get('userID')}',
            `battle_hp` = '$bot[hp]'
            
            ON DUPLICATE KEY 
                UPDATE `battle_hp` = '$bot[hp]'

Add another unique key (assing_bot + assign_user) to the table.