“Update the Prices in a Database!”
$db = DBI->connect('dbi:ODBC:PRICE', 'user', 'password',
$upd = $db->prepare('UPDATE prices SET price=? WHERE prod=?');
$ins = $db->prepare('INSERT INTO prices(prod,price) VALUES (?,?)');
$rows = $upd->execute($price, $prod);
$ins->execute($prod,$price) if $rows == 0;
Notes:
Here we add just 8 lines to store the prices in the database.
The code not only updates prices for products already in the database but also inserts new records for any products not in the database.