vendredi 3 juillet 2015

MySQL equivelant of SQLite INSERT or REPLACE INTO

I'm moving some old code from SQLite to my website to be accessed through a website. One of the queries that I used quite often was the INSERT or REPLACE INTO query, which checked to see if a row existed in the table (Based on the first value) and if it did, it would replace the data in that row with the row specified in the VALUES. However if the row was not found it would INSERT the row into the table.

Query Example (Reduced):

INSERT or REPLACE INTO player_currency (player_id, gold) VALUES (1, 500)

This would find the player with an ID of 1 and set his gold to 500, regardless as to if he was in the table before or not.

I'm not sure if it matters, but I'm using XAMMP 5.6.8 (I've added PHP to the tags considering that's what's being used to connect to the database, feel free to remove it if it doesn't belong)

  • Dabatase Connection: (PHP) PDO Library
  • MySQL Version: 5.6.24
  • PhpMyAdmin Version: 4.4.3

Aucun commentaire:

Enregistrer un commentaire