Check of mysql record



  • I'm writing my three-wheeled CRUD. The following questions have been raised: I want INSERT and UPDATE operations to be carried out in one of the functions of the ventration setEntry(s) (i understand that the logic of operations is divided for safety, but I will try to find out how appropriate this exercise is?

    And the second question is part of the data in the new entry (setEntry()) should be determined whether the record is available at all, but it is already two requests - it is advisable to load mysql?

    And in fact, how better to make this setEntry so that, depending on the record, it generates either INSERT or UPDATE.



  • Extended syntax of INSERT INTO operator

    INSERT INTO tablename
    SET
        key_field = 1,
        data_field1 = 2,
        data_field2 = 3
    ON DUPLICATE KEY UPDATE
        data_field1 = 2,
        data_field2 = 3;
    

    In this case, the key recording key_field = 1 It'll be added if it didn't exist before, and if it already exists, it'll be updated.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2