Search

I have a field extension that is currently utilizing Symphony::Database()->update() to update a field. I need to fix a bug so that a new row is added to the table if one doesn't exist for that entry (i.e. affects existing Symphony entries). I'm not sure which is the best approach:

  1. Check for existing row and execute update if it exists, otherwise create a new row.
  2. Delete any existing row and create a new row.

Is there a preference or best practice here?

Usually I use insert - with update set to true. If you would know/set the id/pk that is.

Usually I use insert - with update set to true. If you would know/set the id/pk that is.

Exactly what I needed. I overlooked this at first, but further investigation into MySQL's ON DUPLICATE KEY UPDATE and it became clear.

Cheers!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details