After mysqlUPDATE, use mysql_affected_rows to determine whether the data is successful. if no data is inserted, the result is incorrect. the number of table rows doubles. the code is as follows: {code ...} after mysql is updated, use mysql_affected_rows to determine whether the operation is successful. If no result is displayed, INSERT. The result is incorrect. the number of table rows doubles. the code is as follows:
// Write data to the database function save_db ($ currencyname_en, $ currencyname_cn, $ buyingrate, $ sellingrate, $ middlerate) {// UPDATE $ query_update = 'update '. TABLENAME. 'set '. 'bucket = '. $ buyingrate. ','. 'sellingrate = '. $ sellingrate. ','. 'middlerate = '. $ middlerate. ','. 'lastupdatetime = "'. date ('Y-m-d H: I: S', time ()). '"'. 'Where currencyname_en = "'. $ currencyname_en. '"'; mysql_query ($ query_update); if (mysql_a Ffected_rows ()! = 1) // update failed. try to INSERT {$ query_insert = 'Insert '. TABLENAME. '(currencyname_en, currencyname_cn, buyingrate, sellingrate, middlerate, lastupdatetime) VALUES ("'. $ currencyname_en. '","'. $ currencyname_cn. '","'. $ buyingrate. '","'. $ sellingrate. '","'. $ middlerate. '","'. date ('Y-m-d H: I: S', time ()). '")'; mysql_query ($ query_insert);} if (mysql_affected_rows ()! = 1) {$ err. ="
Insert or update ". $ currencyname_en."-". $ key." currencyname_cn ";}}
Reply content:
After mysql is updated, use mysql_affected_rows to determine whether the operation is successful. If no result is displayed, INSERT. The result is incorrect. the number of table rows doubles. the code is as follows:
// Write data to the database function save_db ($ currencyname_en, $ currencyname_cn, $ buyingrate, $ sellingrate, $ middlerate) {// UPDATE $ query_update = 'update '. TABLENAME. 'set '. 'bucket = '. $ buyingrate. ','. 'sellingrate = '. $ sellingrate. ','. 'middlerate = '. $ middlerate. ','. 'lastupdatetime = "'. date ('Y-m-d H: I: S', time ()). '"'. 'Where currencyname_en = "'. $ currencyname_en. '"'; mysql_query ($ query_update); if (mysql_a Ffected_rows ()! = 1) // update failed. try to INSERT {$ query_insert = 'Insert '. TABLENAME. '(currencyname_en, currencyname_cn, buyingrate, sellingrate, middlerate, lastupdatetime) VALUES ("'. $ currencyname_en. '","'. $ currencyname_cn. '","'. $ buyingrate. '","'. $ sellingrate. '","'. $ middlerate. '","'. date ('Y-m-d H: I: S', time ()). '")'; mysql_query ($ query_insert);} if (mysql_affected_rows ()! = 1) {$ err. ="
Insert or update ". $ currencyname_en."-". $ key." currencyname_cn ";}}
INSERT INTO table(...)VALUES(...)ON DUPLICATE KEY UPDATE field1 = ?, field2 = ?, ...
Will this be simpler?