Thor
Honorary Master
- Joined
- Jun 5, 2014
- Messages
- 44,236
I am in need of guidance again.
I want to add the currencies into the database, but if the currency already exists then I just want the record of the existing currency to be updated.
I read about "ON DUPLICATE KEY" on http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html but to be honest that manual is just overwhelming, my question is, what is the KEY? How do SQL know the KEY is duplicate I don't understand how the KEY works?
This is my current statement:
I want to add the currencies into the database, but if the currency already exists then I just want the record of the existing currency to be updated.
I read about "ON DUPLICATE KEY" on http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html but to be honest that manual is just overwhelming, my question is, what is the KEY? How do SQL know the KEY is duplicate I don't understand how the KEY works?
This is my current statement:
PHP:
$sql = "UPDATE `currency` SET currency_price = :currency_price, currency_percentage = :currency_percentage, currency_history = :currency_history WHERE currency_name = :currency_name";
$statement = $db->prepare($sql);
$statement->execute(array(':currency_name' => $currency_name, ':currency_price' => $currency_price, ':currency_percentage' => $currency_percentage, ':currency_history' => $currency_history));

